Skip to content

Commit 725e512

Browse files
committed
Description to some attributes in Model.
1 parent 620a65b commit 725e512

File tree

1 file changed

+90
-2
lines changed

1 file changed

+90
-2
lines changed

lib/Cake/Model/Model.php

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class Model extends Object {
4646
/**
4747
* The name of the DataSource connection that this Model uses
4848
*
49+
* The value must be an attribute name that you defined in `app/Config/database.php`
50+
* or created using `ConnectionManager::create()`.
51+
*
4952
* @var string
5053
* @link http://book.cakephp.org/view/1057/Model-Attributes#useDbConfig-1058
5154
*/
@@ -62,6 +65,8 @@ class Model extends Object {
6265
/**
6366
* Custom display field name. Display fields are used by Scaffold, in SELECT boxes' OPTION elements.
6467
*
68+
* This field is also used in `find('list')` that has no `fields` associated.
69+
*
6570
* @var string
6671
* @link http://book.cakephp.org/view/1057/Model-Attributes#displayField-1062
6772
*/
@@ -107,8 +112,91 @@ class Model extends Object {
107112
protected $_schema = null;
108113

109114
/**
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
112200
*
113201
* @var array
114202
* @link http://book.cakephp.org/view/1057/Model-Attributes#validate-1067

0 commit comments

Comments
 (0)