I want to ovveride the default url() validation method in CakePHP, since it does not allow the use of ~ inside urls. I thought it would be enough to declare a url() method in AppModel, but it seems that core methods have the precedence with respect to user defined ones.
I think (but I have not tried) one possible way would be to use
$validate = array('url' => array(
'rule' => array('Userdefined', 'url'),
'message' => 'This is not an URL!!!'
));
or something like that (what is the correct sintax?). But this is not completely satisfying.
Indeed I pass the $validate variable as a JSON object to my javascript, and then I do client validation accordingly. Basically I have rewritten part of the CakePHP validation automagic in javascript. So I really want to have
$validate = array('url' => array(
'rule' => 'url',
'message' => 'This is not an URL!!!'
));
in order not to break client-side validation.
EDIT: It turns out I were wrong. The problem is that methods in Validation are called differently from methods in Model, so one has to pay attention when copying/pasting.
The first difference is that $check will now be an array instead of a string, but this I already figured out. What I did not realize is that another array of parameters is passed to Validation methods in Model. Since the signature of url() was
url($check, $strict = false)
the result was that $strict always had the value true, thereby requiring full URLs with protocol prefix. Seeing that the intended URL with tilde was not validating I assumed that the problem was that CakePHP still used the old method.