Syntax of using criteria in CExistValidator

Hello

I am struggeling with some of the validators and their syntax to use.

I am lost with array of array of array…

So what is the right syntax for the line with the criteria if I want to do a findByAttributes?

I have searched this forum, but I have not found any working example of this one.

Could anybody point me in the right direction?


                        

array('image1, image2, image3, image4, image5, image6', 'CExistValidator', array(

                            'attributeName'=>'id',

                            'className'=>'application.models.BattleImage',

                            'criteria' => "findByAttributes(array('battle_id'=>4)",

                            'message'=>'This id is not an BattleImage'

                            )

),

Thanks for any hints.

gb5256




array('image1, image2, image3, image4, image5, image6', 'CExistValidator', array(

    'attributeName'=>'id',

    'className'=>'application.models.BattleImage',

    'criteria' => array(

      'condition'=>'battle_id=4',

    ),

    'message'=>'This id is not an BattleImage'

  )

),

Hello,

thanks for your answer.

But that one is now throwing this error:

Property "CExistValidator.0" is not defined.

Any ideas?

gb5256




array('image1, image2, image3, image4, image5, image6', 'CExistValidator',

    'attributeName'=>'id',

    'className'=>'application.models.BattleImage',

    'criteria' => array(

      'condition'=>'battle_id=4',

    ),

    'message'=>'This id is not an BattleImage'

),

You had a nested array, I don’t think that is valid validator syntax.

Hello,

the CRITERIA is an array as seen here:

http://www.yiiframework.com/doc/api/1.1/CExistValidator#criteria-detail

So the nested array should not be a problem.

Any ideas?

Does anybody have a working example on this one?

gb5256

???

Did you try Luke’s code?

As they say - You can lead a horse to water…

The ability to read carefully is really important, as I have proven for myself right now once again.

Shame on me.

So, Luke was right. His code works.

Thanks Luke. :rolleyes: :rolleyes:

gb5256