Maximum power for your validation rules

I already postet an article about custom validation rules some time ago here.
In this post I introduce some of my custom rules which come in handy quite often.

For being able to use it in different projects I do not use the AppModel for it but a plugin Model class. The AppModel then extends this MyModel class.
I do not want to post the methods here in the blog because they might change over time. You can find the current source code at github.
For Cake2.x the class is: MyModel.

Just make sure recursive/contain is correctly set up and it should all work out just fine.

Note: There is now also a contemporary 2.x behavioral approach to this. And the core rule unique is also supposed to be able to check for multiple dependent fields via array syntax. Never tried that, though.

Validating urls

The core rule does not validate "deep" – meaning it cannot check if the url is actually accessible/correct.
My custom rule works like this:

By default, it will check deep and make sure the url actually exists.
With the autoComplete param you can be more flexible with urls that are missing "http://" etc (note/todo: it would be even better if it would save the autocompleted string). Especially in combination with strict=>true.

Validating identical

As you can see this rule comes in handy if you need to confirm a string to another in the post data. Simply pass the field name along as second param.

Last Words

Hopefully many other cake developers find those enhanced rules useful and maybe they set the core team thinking about implementing some of the features in the future versions of cake.

Please note:
Some of the internal methods, constants etc used might be not available without stuff from my Tools plugin.
Those validation methods above might have to be adjusted to your application. Same goes for the test case which uses some of my own methods/libs to work with.