CakePHP Use validation rule outside model

Recently I wanted to incorporate CakePHP’s URL validator inside my own validation rule. To do this, I used App::Import. This allows you to use CakePHP’s validation rules inside your own validation rule, or wherever you want.

App::import('Core', 'Validation');
$isStrictUrl = Validation::url($value, true);

One response to “CakePHP Use validation rule outside model”

  1. I tried above code but it didn’t work for me. App::uses('Validation', 'Utility'); worked for me.

Leave a Reply

Your email address will not be published. Required fields are marked *