I have some validation methods that I need to use for multiple models. For example validation of phone numbers can be shared across multiple models.
I understand from http://www.yiiframework.com/wiki/56/ I can create an extension that can be used by multiple models, for example:
array('phone', 'ext.Validate.Validate'),
I have modified this line a few times and can confirm it is hitting the right file.
With the following in Validate.php
class Validate
I get the error Call to undefined method Validate::applyTo()
, therefore I have changed it to
class Validate extends CValidator
As suggested by the link above, however I now get the error:
Class Validate contains 1 abstract method
Here is the file as it stands:
<?php
class Validate extends CValidator
{
public function phone($phone)
{
if(!ctype_digit($phone))
{
$this->addError($phone, Yii::t('flash','flash.not_authorised',array('{attribute}'=>$phone)).' '.ucfirst(str_replace('_', ' ', $phone)).' field');
}
else
{
return true;
}
}
}
Can someone point me in the right direction as to how I can have a shared validation between multiple methods using the above.