Accessing Model attribute inside function rules()


I want to use a custom error message while evaluating a database field.

So inside the public function rules()

i am trying this …

array(‘lpno’,‘unique’,‘caseSensitive’=>‘false’,‘message’=>‘Specified License plate -’.$this->lpno.’- number is already on file.’)

The value $this->lpno wont get appeneded to the message.


if i use it like this , it is able to pick up the value. why is this happening ?


public function checkunique()


if ($this->lpno == 'DEL-210')

     $this->addError('lpno',Specified License plate -'.$this->lpno.'- number is already on file.');




Use the {value} placeholder in your message.


this worked like a charm…

now i could do this …

array(‘lpno’,‘unique’,‘caseSensitive’=>‘false’,‘message’=>’{value} number is already on file.’)

By the way, where is the documentation pertaining to this in the yii documentation ?

thanks very much


I’ve found this in the source of the CUniqueValidator class.

May be you should create a yiidoc ticket about this.

Thanks a lot. Yes, i have added the ticket.