Accessing Model attribute inside function rules()

Hello,

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.

But

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

array(‘lpno’,‘checkunique’),

public function checkunique()

{

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


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

}

thanks

Arvind

Use the {value} placeholder in your message.

Great…

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

Arvind

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.