Reputation: 83
I'm going trough the CakePHP tutorial, and I'm at the beginning of the Simple Authorization app. There is the following code, relative to the model for the users table:
public $validate = array(
’username’ => array(
’required’ => array(
’rule’ => array(’notEmpty’),
’message’ => ’A username is required’
)
),
I went trough some of the Data Validation help within the Wiki, but I could not understand why is the 'rule'array nested under the 'required' array? I know that required is a separate function regarding whether there is an array key with the same name in the data block being saved, so it would definitely be ruled out by the "notEmpty" rule following it. At that point I'm guessing that it is just a rule name and it doesn't really change anything. Am I wrong?
Upvotes: 2
Views: 421
Reputation: 11855
Not sure how else to answer but, no, you are not wrong. The 'required' as it appears in your example is simply the name of the rule.
Personally, I tend to name my rules numerically to avoid this kind of confusion.
public $validate = array(
'username'=>array(
'one'=>array(
'rule'=>'notEmpty',
'message'=>'Please enter a username',
'required'=>true
)
),
'email'=>array(
'rule'=>'notEmpty',
'message'=>'Please enter an email address',
'required'=>true
)
);
These two rules are the same, but the first one allows for multiple rules to be added.
Upvotes: 5