Yii Framework Forum: Validation rule message - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Validation rule message Rate Topic: -----

#1 User is offline   jsoo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-March 10
  • Location:Durham, NC, USA

Posted 15 March 2010 - 12:16 PM

In a CUniqueValidator rule, I am trying to include some additional attributes in the message. That is, I'd like to do something like this for a rule:

array(
    'fooId',
    'unique',
    'criteria'=>array(
        'condition'=>'barId='.$this->barId,
    ),
    'message'=>$this->getRelated('foo')->fullName.' already taken',
),


However, this gives me a "Trying to get property of non-object" error.

Experimenting, I found that this works:

    'message'=>Foo::model()->findByPk(47)->fullName.' already taken',


as does this:

    'message'=>$this->fooId.' already taken',


but not this:

    'message'=>Foo::model()->findByPk($this->fooId)->fullName.' already taken',


I'm stumped. In the last case, $this->fooId ends up as NULL in the findByPk query.
0

#2 User is offline   jsoo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-March 10
  • Location:Durham, NC, USA

Posted 15 March 2010 - 03:09 PM

I should add that this is being used to create multiple new records at once, and that I am using Form Builder. So the issue probably lies somewhere in the function I am using to loop over the $_POST array data, validating each new model.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users