CValidator.php addError() add {value} placeholder

/framework/validators/CValidator.php

line: 194


protected function addError($object,$attribute,$message,$params=array())

{

    $params['{attribute}']=$object->getAttributeLabel($attribute);

    $object->addError($attribute,strtr($message,$params));

}

change to:


protected function addError($object,$attribute,$message,$params=array())

{

    $params['{attribute}']=$object->getAttributeLabel($attribute);

    $params['{value}']=$object->getAttribute($attribute);

    $object->addError($attribute,strtr($message,$params));

}

CActiveRecord中有getAttribute(),但从CFormModel中继承的话没有.

所以应该这样




protected function addError($object,$attribute,$message,$params=array())

	{

		$params['{attribute}']=$object->getAttributeLabel($attribute);

		$params['{value}']=$object->{$attribute};

		$object->addError($attribute,strtr($message,$params));

	}



所言极是,是我考虑不够周到

我想是否再加个判断? 假如 CFormModel 里面没有这个属性?

May I ask anybody for some help with params/placeholder - array last attribute of addError (CValidate)? It is usualy omitted (blank), but I would like to control of the place the error is displayed. In my case error/message breaks the layout of small XLoginForm/Portlet. Has anybody got/put some clear example of usage off this rare used parameter/attribute of adError? I will be grateful… very very:)

Is there any Good Soul to help me?

How to apply the $params - last parameter (array) of addError to control the placeholder of the error-message?

CValidator::addError() - http://www.yiiframework.com/doc/api/1.1/CValidator#addError-detail

Note that the last parameter $param are the values for the placeholders… not the placeholders…

If you need to control the placeholders you can do it on the 3rd parameter $message… check the documentation for message - http://www.yiiframework.com/doc/api/1.1/CValidator#message-detail

So you can use something like this "The attribute {attribute} is not good"