{1078} - 3.7.8 Model Attributes
For a complete list of model attributes and their descriptions visit the CakePHP API. Check out http://api.cakephp.org/1.2/class_model.html.
The name of the database configuration this model uses. Configurations are specified in /app/config/database.php as class variables. Defaults to ‘default.’
The name of the database table this model uses. The default table used is the lower-cased, plural version of the model’s classname. Set this attribute to the name of an alternate table, or set it to false if you wish the model to have no database relation at all.
If the model is tied to a database table, this attribute holds the name of the column of the tables primary key. Defaults to ‘id’.
This attribute is used to define the field the model will use for display in scaffolding elements. When associated data is presented (i.e., which Ingredient you’d like to associate to a Recipe) scaffolding will use the row’s ID, ‘name’, or ‘title’ fields unless $displayField has been specified.
An integer specifying the number of levels you wish CakePHP to fetch associated model data in find() and findAll() operations.
Imagine your application features Groups which have many Users which in turn have many Articles. You can set $recursive to different values based on the amount of data you want back from a $this->Group->find() call:
- 0 - Cake fetches Group data
- 1 - Cake fetches a Group and its associated Users
- 2 - Cake fetches a Group, its associated Users, and the Users' associated Articles
Set it no higher than you need–having CakePHP fetch data you aren’t going to use unnecessarily slows your app.
The default ordering of data for any find operation. Possible values include:
$order = "field"
$order = "Model.field";
$order = "Model.field asc";
$order = "Model.field ASC";
$order = "Model.field DESC";
$order = array("Model.field" => "asc", "Model.field2" => "DESC");
$order = "field"$order = "Model.field";$order = "Model.field asc";$order = "Model.field ASC";$order = "Model.field DESC";$order = array("Model.field" => "asc", "Model.field2" => "DESC");
Value of the primary key ID of the record that this model is currently pointing to. If you are saving model data inside of a loop, set $id to null ($this->ModelName->id = null) in order to ready the model class for the next set of data.
The container for the model’s fetched data. While data returned from a model class is normally used as returned from a find() call, you may need to access information stored in $data inside of model callbacks.
Contains metadata describing the model’s database table fields. Each field is described by:
- name
- type (integer, string, datetime, etc.)
- null
- default value
- length
This attribute holds rules that allow the model to make data validation decisions before saving. Keys named after fields hold regex values allowing the model to try to make matches.
For more information on validation, see the Data Validation chapter later on in this manual.
The name of this model. CakePHP model names are CamelCased and singular. CakePHP users on PHP4 should always declare $name in order to avoid the quirks involved with PHP4 class-naming.
If set to true, data fetched by the model during a single request is cached. This caching is in-memory only, and only lasts for the duration of the request. Any duplicate requests for the same data is handled by the cache.
These model attributes will be covered later in this chapter. They hold arrays that define how this model is related to others.
This attribute is also covered later on. The $actsAs attribute stores the names of Behaviors this model uses.
{2105} - 3.7.8 Model Attributes
Model attributes allow you to set properties that can override the default model behavior.
For a complete list of model attributes and their descriptions visit the CakePHP API. Check out http://api.cakephp.org/1.2/class_model.html.
Differences
| Lines: 1-123 | Lines: 1-5 | ||
| <title>Model Attributes</title> | <title>Model Attributes</title> | ||
| - | <p> For a complete list of model attributes and their descriptions visit the CakePHP API. Check out <a href="http://api.cakephp.org/1.2/class_model.html">http://api.cakephp.org/1.2/class_model.html</a>. </p> <div class="method">r /> $useDbConfig </div> <p> The name of the database configuration this model uses. Configurations are specified in /app/config/database.php as class variables. Defaults to ‘default.’ </p> <div class="method">r /> $useTabler /></div> <p> The name of the database table this model uses. The default table used is the lower-cased, plural version of the model’s classname. Set this attribute to the name of an alternate table, or set it to <em>false</em> if you wish the model to have no database relation at all. </p> <div class="method"> $primaryKey </div> <p>r /> If the model is tied to a database table, this attribute holds the name of the column of the tables primary key. Defaults to ‘id’. </p> <div class="method"> $displayField </div> <p> This attribute is used to define the field the model will use for display in scaffolding elements. When associated data is presented (i.e., which Ingredient you’d like to associate to a Recipe) scaffolding will use the row’s ID, ‘name’, or ‘title’ fields unless $displayField has been specified. </p> <div class="method"> $recursive /></div> <p> An integer specifying the number of levels you wish CakePHP to fetch associated model data in find() and findAll() operations. </p> <p> Imagine your application features Groups which have many Users which in turn have many Articles. You can set $recursive to different values based on the amount of data you want back from a $this->Group->find() call: </p> <ul> <li>0 - Cake fetches Group data </li> <li>1 - Cake fetches a Group and its associated Users </li> <li>2 - Cake fetches a Group, its associated Users, and the Users' associated Articles </li> </ul> <p> Set it no higher than you need–having CakePHP fetch data you aren’t going to use unnecessarily slows your app. </p> <div class="method"> $order </div> <p> The default ordering of data for any find operation. Possible values include: /></p> <pre> $order = "field" $order = "Model.field"; $order = "Model.field asc"; $order = "Model.field ASC"; $order = "Model.field DESC"; $order = array("Model.field" =&gt; "asc", "Model.field2" => "DESC"); </pre> <p> Value of the primary key ID of the record that this model is currently pointing to. If you are saving model data inside of a loop, set $id to null ($this->ModelName->id = null) in order to ready the model class for the next set of data. /></p> <div class="method"> $data </div> <p> The container for the model’s fetched data. While data returned from a model class is normally used as returned from a find() call, you may need to access information stored in $data inside of model callbacks. </p> <div class="method"> $_schema </div> <p> Contains metadata describing the model’s database table fields. Each field is described by: /></p> <ul> <li>name </li> <li>type (integer, string, datetime, etc.) </li> <li>null </li> <li>default value </li> <li>length </li> </ul> <div class="method"> $validate </div> <p> This attribute holds rules that allow the model to make data validation decisions before saving. Keys named after fields hold regex values allowing the model to try to make matches. </p> <p> For more information on validation, see the Data Validation chapter later on in this manual. </p> <div class="method">r /> $name </div> /><p> The name of this model. CakePHP model names are CamelCased and singular. CakePHP users on PHP4 should always declare $name in order to avoid the quirks involved with PHP4 class-naming. /></p> <div class="method"> $cacheQueries </div> <p> If set to true, data fetched by the model during a single request is cached. This caching is in-memory only, and only lasts for the duration of the request. Any duplicate requests for the same data is handled by the cache. </p> <div class="method"> $belongsTo, $hasOne, $hasMany, $hasAndBelongsToMany </div> <p> These model attributes will be covered later in this chapter. They hold arrays that define how this model is related to others. </p> <div class="method"> $actsAs </div> <p> This attribute is also covered later on. The $actsAs attribute stores the names of Behaviors this model uses. </p> |
+ | <p>Model attributes allow you to set properties that can override the default model behavior.</p> <p>For a complete list of model attributes and their descriptions visit the CakePHP API. Check out <a href="http://api.cakephp.org/1.2/class_model.html">http://api.cakephp.org/1.2/class_model.html</a>.</p> |
