@@ -46,6 +46,9 @@ class Model extends Object {
46
46
/**
47
47
* The name of the DataSource connection that this Model uses
48
48
*
49
+ * The value must be an attribute name that you defined in `app/Config/database.php`
50
+ * or created using `ConnectionManager::create()`.
51
+ *
49
52
* @var string
50
53
* @link http://book.cakephp.org/view/1057/Model-Attributes#useDbConfig-1058
51
54
*/
@@ -62,6 +65,8 @@ class Model extends Object {
62
65
/**
63
66
* Custom display field name. Display fields are used by Scaffold, in SELECT boxes' OPTION elements.
64
67
*
68
+ * This field is also used in `find('list')` that has no `fields` associated.
69
+ *
65
70
* @var string
66
71
* @link http://book.cakephp.org/view/1057/Model-Attributes#displayField-1062
67
72
*/
@@ -107,8 +112,91 @@ class Model extends Object {
107
112
protected $ _schema = null ;
108
113
109
114
/**
110
- * List of validation rules. Append entries for validation as ('field_name' => '/^perl_compat_regexp$/')
111
- * that have to match with preg_match(). Use these rules with Model::validate()
115
+ * List of validation rules. It must be an array with the field as key and the
116
+ * value one of possiblity below:
117
+ *
118
+ * ### Validating using regular expressions
119
+ *
120
+ * {{{
121
+ * public $validate = array(
122
+ * 'name' => '/^[a-z].+$/i'
123
+ * );
124
+ * }}}
125
+ *
126
+ * ### Validating using methods (no parameters)
127
+ *
128
+ * {{{
129
+ * public $validate = array(
130
+ * 'name' => 'notEmpty'
131
+ * );
132
+ * }}}
133
+ *
134
+ * ### Validating using methods (with parameters)
135
+ *
136
+ * {{{
137
+ * public $validate = array(
138
+ * 'age' => array(
139
+ * 'rule' => array('between', 5, 25)
140
+ * )
141
+ * );
142
+ * }}}
143
+ *
144
+ * ### Validating using custom method
145
+ *
146
+ * {{{
147
+ * public $validate = array(
148
+ * 'password' => array(
149
+ * 'rule' => array('customValidation')
150
+ * )
151
+ * );
152
+ * public function customValidation($data) {
153
+ * // $data will contain array('password' => 'value')
154
+ * if (isset($this->data[$this->alias]['password2'])) {
155
+ * return $this->data[$this->alias]['password2'] === current($data);
156
+ * }
157
+ * return true;
158
+ * }
159
+ * }}}
160
+ *
161
+ * ### Validations with messages
162
+ *
163
+ * The messages will be used in Model::$validationErrors and can be used in the FormHelper
164
+ *
165
+ * {{{
166
+ * public $validate = array(
167
+ * 'age' => array(
168
+ * 'rule' => array('between', 5, 25),
169
+ * 'message' => array('The age must be between %d and %d.')
170
+ * )
171
+ * );
172
+ * }}}
173
+ *
174
+ * ### Multiple validations to the same field
175
+ *
176
+ * {{{
177
+ * public $validate = array(
178
+ * 'login' => array(
179
+ * array(
180
+ * 'role' => 'alphaNumeric',
181
+ * 'message' => 'Only alphabets and numbers allowed',
182
+ * 'last' => true
183
+ * ),
184
+ * array(
185
+ * 'role' => array('minLength', 8),
186
+ * 'message' => array('Minimum length of %d characters')
187
+ * )
188
+ * )
189
+ * );
190
+ * }}}
191
+ *
192
+ * ### Valid keys in validations
193
+ *
194
+ * - `role`: String with method name, regular expression (started by slash) or array with method and parameters
195
+ * - `message`: String with the message or array if have multiple parameters. See http://php.net/sprintf
196
+ * - `last`: Boolean value to indicate if continue validating the others rules if the current fail [Default: true]
197
+ * - `required`: Boolean value to indicate if the field must be present on save
198
+ * - `allowEmpty`: Boolean value to indicate if the field can be empty
199
+ * - `on`: Possible values: `update`, `create`. Indicate to apply this rule only on update or create
112
200
*
113
201
* @var array
114
202
* @link http://book.cakephp.org/view/1057/Model-Attributes#validate-1067
0 commit comments