Sintaxys of Rules validation, elements separated by comma or not?

Hi , what is the correct sintaxys for write validation rules ?

by example . . .

array(‘first_name, date_update, date_birthdate ,compliance’,‘length’, ‘max’=>1)


array(‘first_name’, ‘date_update’, ‘date_birthdate’ ,‘compliance’,‘length’, ‘max’=>1)

Both sintaxys are valid ?

or for second sintaxys we need a special configuration of PHP version ?

my php configuration:
PHP Version 5.6.40-0+deb8u12
Linux debiandb 4.9.0-18-amd64 #1 SMP Debian 4.9.303-1
Apache 2.0

Yii Version 1.1.13

Note: with the second sintaxys the app show errors, when we change to the first sintaxys all work good !

Described here

Each rule returned by rules() must be of the following format:
array(‘AttributeList’, ‘Validator’, ‘on’=>‘ScenarioList’, …additional options)
where AttributeList is a string of comma-separated attribute names which need to be validated according to the rule;

1 Like

It should be:

[['first_name', 'date_update', 'date_birthdate' ,'compliance'], 'length', 'max' => 1]

Not that list of attributes is wrapped in array.

Thank you for the official reference @tri :slight_smile:

thank you @rob006 , this is just like i was thinking . .

array(array('first_name', 'date_update', 'date_birthdate' ,'compliance'), 'length', 'max' => 1)

Can or should? (I do not remember)

Yii 2.0 dokumentation:

In Yii 1.1 you can pass attributes either as array or string (multiple attributes separated by comma). In Yii 2 you should use array (although you can pass string, but it will work only for single attribute, you can’t pass multiple attributes in that way).

1 Like

Yes, I just looked it up:

$attributes=preg_split(’/\s*,\s*/’,trim($attributes, " \t\n\r\0\x0B,"),-1,PREG_SPLIT_NO_EMPTY);