mahdi_1986
دوشنبه 02 تیر 1393, 21:39 عصر
سلام دوستان
من برای یک فیلد نیاز به یک validation خاص دارم مطابق با لینک زیر http://www.yiiframework.com/wiki/168/create-your-own-validation-rule/
ساختم
class AccountNumber extends CValidator
{
private $MIN_COUNT = 3;
private $MAX_COUNT = 10;
/**
* Validates a single attribute.
* This method should be overridden by child classes.
* @param CModel $object the data object being validated
* @param string $attribute the name of the attribute to be validated.
*/
public function validateAttribute($object, $attribute)
{
$this->addError($object,$attribute, 'Account Number is Invalid');
}
}
و در Rule هم به صورت زیر اضافه کردم:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('account_number', 'ext.AccountNumber'),
array('account_number', 'required'),
);
}
ولی هیچ چیزی بر رو فرم در موقع خطا نشون نمیده (اصلن خطا فراخوانی نمیشود!) کسی میدونه چرا؟؟؟
Model هم از ActiveRecord وارثت برده است
کسی میدونه مشکل از چیه؟؟
من برای یک فیلد نیاز به یک validation خاص دارم مطابق با لینک زیر http://www.yiiframework.com/wiki/168/create-your-own-validation-rule/
ساختم
class AccountNumber extends CValidator
{
private $MIN_COUNT = 3;
private $MAX_COUNT = 10;
/**
* Validates a single attribute.
* This method should be overridden by child classes.
* @param CModel $object the data object being validated
* @param string $attribute the name of the attribute to be validated.
*/
public function validateAttribute($object, $attribute)
{
$this->addError($object,$attribute, 'Account Number is Invalid');
}
}
و در Rule هم به صورت زیر اضافه کردم:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('account_number', 'ext.AccountNumber'),
array('account_number', 'required'),
);
}
ولی هیچ چیزی بر رو فرم در موقع خطا نشون نمیده (اصلن خطا فراخوانی نمیشود!) کسی میدونه چرا؟؟؟
Model هم از ActiveRecord وارثت برده است
کسی میدونه مشکل از چیه؟؟