Aro Class Info:
- Class Declaration:
class Aro extends AclNode implements CakeEventListener
- File name:
- Cake/Model/Aro.php
- Description:
Access Request Object
- Class Inheritance
- Interfaces Implemented
- CakeEventListener
- Package
- Cake.Model
Properties:
-
actsAs array
ACL models use the Tree behavior
-
alias string
Alias name for model.
-
_associationKeys array
Default list of association keys.
-
_associations array
Holds provided/generated association key names and other data for all associations.
-
__backAssociation array
Holds model associations temporarily to allow for dynamic (un)binding.
-
__backContainableAssociation array
Back containable association
-
__backInnerAssociation array
Back inner association
-
__backOriginalAssociation array
Back original association
-
Behaviors BehaviorCollection
Holds the Behavior objects currently bound to this model.
-
belongsTo array
Detailed list of belongsTo associations.
Basic usage
public $belongsTo = array('Group', 'Department');Detailed configuration
public $belongsTo = array( 'Group', 'Department' => array( 'className' => 'Department', 'foreignKey' => 'department_id' ) );Possible keys in association
className: the classname of the model being associated to the current model. If you're defining a 'Profile belongsTo User' relationship, the className key should equal 'User.'foreignKey: the name of the foreign key found in the current model. This is especially handy if you need to define multiple belongsTo relationships. The default value for this key is the underscored, singular name of the other model, suffixed with '_id'.conditions: An SQL fragment used to filter related model records. It's good practice to use model names in SQL fragments: 'User.active = 1' is always better than just 'active = 1.'type: the type of the join to use in the SQL query, default is LEFT which may not fit your needs in all situations, INNER may be helpful when you want everything from your main and associated models or nothing at all!(effective when used with some conditions of course). (NB: type value is in lower case - i.e. left, inner)fields: A list of fields to be retrieved when the associated model data is fetched. Returns all fields by default.order: An SQL fragment that defines the sorting order for the returned associated rows.counterCache: If set to true the associated Model will automatically increase or decrease the "[singular_model_name]_count" field in the foreign table whenever you do a save() or delete(). If its a string then its the field name to use. The value in the counter field represents the number of related rows.counterScope: Optional conditions array to use for updating counter cache field.
-
cacheQueries boolean
Explicitly disable in-memory query caching for ACL models
-
cacheSources boolean
Whether or not to cache sources for this model.
-
data array
Container for the data that this model gets from persistent storage (usually, a database).
-
displayField string
Custom display field name. Display fields are used by Scaffold, in SELECT boxes' OPTION elements.
This field is also used in
find('list')when called with no extra parameters in the fields list -
_eventManager CakeEventManager
Instance of the CakeEventManager this model is using to dispatch inner events.
-
findMethods array
List of valid finder method options, supplied as the first parameter to find().
-
findQueryType string
Type of find query currently executing.
-
hasAndBelongsToMany array
AROs are linked to ACOs by means of Permission
-
hasMany array
Detailed list of hasMany associations.
Basic usage
public $hasMany = array('Comment', 'Task');Detailed configuration
public $hasMany = array( 'Comment', 'Task' => array( 'className' => 'Task', 'foreignKey' => 'user_id' ) );Possible keys in association
className: the classname of the model being associated to the current model. If you're defining a 'User hasMany Comment' relationship, the className key should equal 'Comment.'foreignKey: the name of the foreign key found in the other model. This is especially handy if you need to define multiple hasMany relationships. The default value for this key is the underscored, singular name of the actual model, suffixed with '_id'.conditions: An SQL fragment used to filter related model records. It's good practice to use model names in SQL fragments: "Comment.status = 1" is always better than just "status = 1."fields: A list of fields to be retrieved when the associated model data is fetched. Returns all fields by default.order: An SQL fragment that defines the sorting order for the returned associated rows.limit: The maximum number of associated rows you want returned.offset: The number of associated rows to skip over (given the current conditions and order) before fetching and associating.dependent: When dependent is set to true, recursive model deletion is possible. In this example, Comment records will be deleted when their associated User record has been deleted.exclusive: When exclusive is set to true, recursive model deletion does the delete with a deleteAll() call, instead of deleting each entity separately. This greatly improves performance, but may not be ideal for all circumstances.finderQuery: A complete SQL query CakePHP can use to fetch associated model records. This should be used in situations that require very custom results.
-
hasOne array
Detailed list of hasOne associations.
Basic usage
public $hasOne = array('Profile', 'Address');Detailed configuration
public $hasOne = array( 'Profile', 'Address' => array( 'className' => 'Address', 'foreignKey' => 'user_id' ) );Possible keys in association
className: the classname of the model being associated to the current model. If you're defining a 'User hasOne Profile' relationship, the className key should equal 'Profile.'foreignKey: the name of the foreign key found in the other model. This is especially handy if you need to define multiple hasOne relationships. The default value for this key is the underscored, singular name of the current model, suffixed with '_id'. In the example above it would default to 'user_id'.conditions: An SQL fragment used to filter related model records. It's good practice to use model names in SQL fragments: "Profile.approved = 1" is always better than just "approved = 1."fields: A list of fields to be retrieved when the associated model data is fetched. Returns all fields by default.order: An SQL fragment that defines the sorting order for the returned associated rows.dependent: When the dependent key is set to true, and the model's delete() method is called with the cascade parameter set to true, associated model records are also deleted. In this case we set it true so that deleting a User will also delete her associated Profile.
-
id mixed
Value of the primary key ID of the record that this model is currently pointing to. Automatically set after database insertions.
-
_insertID integer
The ID of the model record that was last inserted.
-
name string
Model name
-
order string
The column name(s) and direction(s) to order find results by default.
public $order = "Post.created DESC"; public $order = array("Post.view_count DESC", "Post.rating DESC");
-
primaryKey string
The name of the primary key field for this model.
-
recursive integer
Number of associations to recurse through during find calls. Fetches only the first level by default.
-
_schema array
Field-by-field table metadata.
-
schemaName string
Holds physical schema/database name for this model. Automatically set during Model creation.
-
_sourceConfigured boolean
Has the datasource been configured.
-
table string
Table name for this Model.
-
tablePrefix string
Database table prefix for tables in model.
-
tableToModel array
List of table names included in the model description. Used for associations.
-
useDbConfig string
The name of the DataSource connection that this Model uses
The value must be an attribute name that you defined in
app/Config/database.phpor created usingConnectionManager::create(). -
useTable string
Custom database table name, or null/false if no table association is desired.
-
validate array
List of validation rules. It must be an array with the field name as key and using as value one of the following possibilities
Validating using regular expressions
public $validate = array( 'name' => '/^[a-z].+$/i' );Validating using methods (no parameters)
public $validate = array( 'name' => 'notEmpty' );Validating using methods (with parameters)
public $validate = array( 'age' => array( 'rule' => array('between', 5, 25) ) );Validating using custom method
public $validate = array( 'password' => array( 'rule' => array('customValidation') ) ); public function customValidation($data) { // $data will contain array('password' => 'value') if (isset($this->data[$this->alias]['password2'])) { return $this->data[$this->alias]['password2'] === current($data); } return true; }Validations with messages
The messages will be used in Model::$validationErrors and can be used in the FormHelper
public $validate = array( 'age' => array( 'rule' => array('between', 5, 25), 'message' => array('The age must be between %d and %d.') ) );Multiple validations to the same field
public $validate = array( 'login' => array( array( 'rule' => 'alphaNumeric', 'message' => 'Only alphabets and numbers allowed', 'last' => true ), array( 'rule' => array('minLength', 8), 'message' => array('Minimum length of %d characters') ) ) );Valid keys in validations
rule: String with method name, regular expression (started by slash) or array with method and parametersmessage: String with the message or array if have multiple parameters. See http://php.net/sprintflast: Boolean value to indicate if continue validating the others rules if the current fail [Default: true]required: Boolean value to indicate if the field must be present on saveallowEmpty: Boolean value to indicate if the field can be emptyon: Possible values:update,create. Indicate to apply this rule only on update or create
-
validationDomain string
Name of the validation string domain to use when translating validation errors.
-
validationErrors array
List of validation errors.
-
virtualFields array
Array of virtual fields this model has. Virtual fields are aliased SQL expressions. Fields added to this property will be read as other fields in a model but will not be saveable.
public $virtualFields = array('two' => '1 + 1');Is a simplistic example of how to set virtualFields
-
whitelist array
Whitelist of fields allowed to be saved.
Method Summary:
- afterDelete( )
- afterFind( $results, $primary = false )
- afterSave( $created )
- associations( )
- beforeDelete( $cascade = true )
- beforeFind( $queryData )
- beforeSave( $options = array ( ) )
- beforeValidate( $options = array ( ) )
- bindModel( $params, $reset = true )
- buildQuery( $type = 'first', $query = array ( ) )
- __call( $method, $params )
- _clearCache( $type = NULL )
- _collectForeignKeys( $type = 'belongsTo' )
- __construct( )
- _constructLinkedModel( $assoc, $className = NULL, $plugin = NULL )
- create( $data = array ( ), $filterKey = false )
- _createLinks( )
- deconstruct( $field, $data )
- delete( $id = NULL, $cascade = true )
- deleteAll( $conditions, $cascade = true, $callbacks = false )
- _deleteDependent( $id, $cascade )
- _deleteLinks( $id )
- dispatchMethod( $method, $params = array ( ) )
- escapeField( $field = NULL, $alias = NULL )
- exists( $id = NULL )
- field( $name, $conditions = NULL, $order = NULL )
- _filterResults( $results, $primary = true )
- find( $type = 'first', $query = array ( ) )
- _findCount( $state, $query, $results = array ( ) )
- _findFirst( $state, $query, $results = array ( ) )
- _findList( $state, $query, $results = array ( ) )
- _findNeighbors( $state, $query, $results = array ( ) )
- _findThreaded( $state, $query, $results = array ( ) )
- _generateAssociation( $type, $assocKey )
- __get( $name )
- getAffectedRows( )
- getAssociated( $type = NULL )
- getColumnType( $column )
- getColumnTypes( )
- getDataSource( )
- getEventManager( )
- getID( $list = 0 )
- getInsertID( )
- getLastInsertID( )
- getNumRows( )
- getVirtualField( $field = NULL )
- hasAny( $conditions = NULL )
- hasField( $name, $checkVirtual = false )
- hasMethod( $method )
- implementedEvents( )
- invalidate( $field, $value = true )
- invalidFields( $options = array ( ) )
- isForeignKey( $field )
- __isset( $name )
- isUnique( $fields, $or = true )
- isVirtualField( $field )
- joinModel( $assoc, $keys = array ( ) )
- log( $msg, $type = 2 )
- _mergeVars( $properties, $class, $normalize = true )
- node( $ref = NULL )
- _normalizeXmlData( $xml )
- onError( )
- _prepareUpdateFields( $data )
- query( $sql )
- read( $fields = NULL, $id = NULL )
- requestAction( $url, $extra = array ( ) )
- resetAssociations( )
- save( $data = NULL, $validate = true, $fieldList = array ( ) )
- saveAll( $data = NULL, $options = array ( ) )
- saveAssociated( $data = NULL, $options = array ( ) )
- saveField( $name, $value, $validate = false )
- saveMany( $data = NULL, $options = array ( ) )
- _saveMulti( $joined, $id, $db )
- schema( $field = false )
- set( $one, $two = NULL )
- _set( $properties = array ( ) )
- setDataSource( $dataSource = NULL )
- setInsertID( $id )
- setSource( $tableName )
- _stop( $status = 0 )
- toString( )
- unbindModel( $params, $reset = true )
- updateAll( $fields, $conditions = true )
- updateCounterCache( $keys = array ( ), $created = false )
- validateAssociated( $data, $options = array ( ) )
- validateMany( $data, $options = array ( ) )
- validates( $options = array ( ) )
- _validateWithModels( $options )
afterDelete
topCalled after every deletion operation.
- Method defined in:
- Cake/Model/Model.php on line 3552
afterFind
topCalled after each find operation. Can be used to modify any results returned by find(). Return value should be the (modified) results.
- Parameters:
-
-
mixed $results required
The results of the find operation
-
boolean $primary optional false
Whether this model is being queried directly (vs. being queried as an association)
-
- Method defined in:
- Cake/Model/Model.php on line 3509
- Return
mixed Result of the find operation
- Link
- http://book.cakephp.org/2.0/en/models/callback-methods.html#afterfind
afterSave
topCalled after each successful save operation.
- Parameters:
-
-
boolean $created required
True if this save created a new record
-
- Method defined in:
- Cake/Model/Model.php on line 3532
beforeDelete
topCalled before every deletion operation.
- Parameters:
-
-
boolean $cascade optional true
If true records that depend on this record will also be deleted
-
- Method defined in:
- Cake/Model/Model.php on line 3542
- Return
boolean True if the operation should continue, false if it should abort
- Link
- http://book.cakephp.org/2.0/en/models/callback-methods.html#beforedelete
beforeFind
topCalled before each find operation. Return false if you want to halt the find call, otherwise return the (modified) query data.
- Parameters:
-
-
array $queryData required
Data used to execute this query, i.e. conditions, order, etc.
-
- Method defined in:
- Cake/Model/Model.php on line 3496
- Return
mixed true if the operation should continue, false if it should abort; or, modified $queryData to continue with new $queryData
- Link
- http://book.cakephp.org/2.0/en/models/callback-methods.html#beforefind
beforeSave
topCalled before each save operation, after validation. Return a non-true result to halt the save.
- Parameters:
-
-
array $options optional array ( )
-
- Method defined in:
- Cake/Model/Model.php on line 3521
- Return
boolean True if the operation should continue, false if it should abort
- Link
- http://book.cakephp.org/2.0/en/models/callback-methods.html#beforesave
beforeValidate
topCalled during validation operations, before validation. Please note that custom validation rules can be defined in $validate.
- Parameters:
-
-
array $options optional array ( )
Options passed from model::save(), see $options of model::save().
-
- Method defined in:
- Cake/Model/Model.php on line 3563
- Return
boolean True if validate operation should continue, false to abort
- Link
- http://book.cakephp.org/2.0/en/models/callback-methods.html#beforevalidate
bindModel
topBind model associations on the fly.
If $reset is false, association will not be reset
to the originals defined in the model
Example: Add a new hasOne binding to the Profile model not defined in the model source code:
$this->User->bindModel( array('hasOne' => array('Profile')) );
Bindings that are not made permanent will be reset by the next Model::find() call on this model.
- Parameters:
-
-
array $params required
Set of bindings (indexed by binding type)
-
boolean $reset optional true
Set to false to make the binding permanent
-
- Method defined in:
- Cake/Model/Model.php on line 887
buildQuery
topBuilds the query array that is used by the data source to generate the query to fetch the data.
- Parameters:
-
-
string $type optional 'first'
Type of find operation (all / first / count / neighbors / list / threaded)
-
array $query optional array ( )
Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks)
-
- Method defined in:
- Cake/Model/Model.php on line 2689
- Return
array Query array or null if it could not be build for some reasons
- See
__call
topHandles custom method calls, like findBy<field> for DB models, and custom RPC calls for remote data sources.
- Parameters:
-
-
string $method required
Name of method to call.
-
array $params required
Parameters for the method.
-
- Method defined in:
- Cake/Model/Model.php on line 770
- Return
mixed Whatever is returned by called method
_clearCache
topClears cache for this model.
- Parameters:
-
-
string $type optional NULL
If null this deletes cached views if Cache.check is true Will be used to allow deleting query cache also
-
- Method defined in:
- Cake/Model/Model.php on line 3583
- Return
boolean true on delete
_collectForeignKeys
topCollects foreign keys from associations.
- Parameters:
-
-
string $type optional 'belongsTo'
-
- Method defined in:
- Cake/Model/Model.php on line 2558
- Return
array
_constructLinkedModel
topProtected helper method to create associated models of a given class.
usage: $this->Assoc->modelMethods();
public $hasMany = array('ModelName');
usage: $this->ModelName->modelMethods();
- Parameters:
-
-
string $assoc required
Association name
-
string $className optional NULL
Class name
-
string $plugin optional NULL
name of the plugin where $className is located examples: public $hasMany = array('Assoc' => array('className' => 'ModelName'));
-
- Method defined in:
- Cake/Model/Model.php on line 997
- Return
void
create
topInitializes the model for writing a new record, loading the default values for those fields that are not defined in $data, and clearing previous validation errors. Especially helpful for saving data in loops.
- Parameters:
-
-
mixed $data optional array ( )
Optional data array to assign to the model after it is created. If null or false, schema data defaults are not merged.
-
boolean $filterKey optional false
If true, overwrites any primary key input with an empty value
-
- Method defined in:
- Cake/Model/Model.php on line 1444
- Return
array The current Model::data; after merging $data and/or defaults from database
- Link
- http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-create-array-data-array
_createLinks
topdeconstruct
topDeconstructs a complex data type (array or object) into a single field value.
- Parameters:
-
-
string $field required
The name of the field to be deconstructed
-
mixed $data required
An array or object to be deconstructed into a field
-
- Method defined in:
- Cake/Model/Model.php on line 1190
- Return
mixed The resulting data that should be assigned to a field
delete
topRemoves record for given ID. If no ID is given, the current ID is used. Returns true on success.
- Parameters:
-
-
mixed $id optional NULL
ID of record to delete
-
boolean $cascade optional true
Set to true to delete records that depend on this record
-
- Method defined in:
- Cake/Model/Model.php on line 2379
- Return
boolean True on success
- Link
- http://book.cakephp.org/2.0/en/models/deleting-data.html
deleteAll
topDeletes multiple model records based on a set of conditions.
- Parameters:
-
-
mixed $conditions required
Conditions to match
-
boolean $cascade optional true
Set to true to delete records that depend on this record
-
boolean $callbacks optional false
Run callbacks
-
- Method defined in:
- Cake/Model/Model.php on line 2510
- Return
boolean True on success, false on failure
- Link
- http://book.cakephp.org/2.0/en/models/deleting-data.html#deleteall
_deleteDependent
topCascades model deletes through associated hasMany and hasOne child records.
- Parameters:
-
-
string $id required
ID of record that was deleted
-
boolean $cascade required
Set to true to delete records that depend on this record
-
- Method defined in:
- Cake/Model/Model.php on line 2435
- Return
void
_deleteLinks
topCascades model deletes through HABTM join keys.
- Parameters:
-
-
string $id required
ID of record that was deleted
-
- Method defined in:
- Cake/Model/Model.php on line 2484
- Return
void
dispatchMethod
topCalls a method on this object with the given parameters. Provides an OO wrapper
for call_user_func_array
- Parameters:
-
-
string $method required
Name of the method to call
-
array $params optional array ( )
Parameter list to use when calling $method
-
- Method defined in:
- Cake/Core/Object.php on line 110
- Return
mixed Returns the result of the method call
escapeField
topEscapes the field name and prepends the model name. Escaping is done according to the current database driver's rules.
- Parameters:
-
-
string $field optional NULL
Field to escape (e.g: id)
-
string $alias optional NULL
Alias for the model (e.g: Post)
-
- Method defined in:
- Cake/Model/Model.php on line 3285
- Return
string The name of the escaped field for this Model (i.e. id becomes
Post.id).
exists
topReturns true if a record with particular ID exists.
If $id is not passed it calls Model::getID() to obtain the current record ID, and then performs a Model::find('count') on the currently configured datasource to ascertain the existence of the record in persistent storage.
- Parameters:
-
-
mixed $id optional NULL
ID of record to check for existence
-
- Method defined in:
- Cake/Model/Model.php on line 2579
- Return
boolean True if such a record exists
field
topReturns the contents of a single field given the supplied conditions, in the supplied order.
- Parameters:
-
-
string $name required
Name of field to get
-
array $conditions optional NULL
SQL conditions (defaults to NULL)
-
string $order optional NULL
SQL ORDER BY fragment
-
- Method defined in:
- Cake/Model/Model.php on line 1508
- Return
string field contents, or false if not found
- Link
- http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#model-field
_filterResults
topPasses query results through model and behavior afterFilter() methods.
- Parameters:
-
-
array $results required
Results to filter
-
boolean $primary optional true
If this is the primary model results (results from model where the find operation was performed)
-
- Method defined in:
- Cake/Model/Model.php on line 2933
- Return
array Set of filtered results
find
topQueries the datasource and returns a result set array.
Also used to perform notation finds, where the first argument is type of find operation to perform (all / first / count / neighbors / list / threaded), second parameter options for finding ( indexed array, including: 'conditions', 'limit', 'recursive', 'page', 'fields', 'offset', 'order')
Eg:
find('all', array(
'conditions' => array('name' => 'Thomas Anderson'),
'fields' => array('name', 'email'),
'order' => 'field3 DESC',
'recursive' => 2,
'group' => 'type'
));
In addition to the standard query keys above, you can provide Datasource, and behavior specific keys. For example, when using a SQL based datasource you can use the joins key to specify additional joins that should be part of the query.
find('all', array(
'conditions' => array('name' => 'Thomas Anderson'),
'joins' => array(
array(
'alias' => 'Thought',
'table' => 'thoughts',
'type' => 'LEFT',
'conditions' => '`Thought`.`person_id` = `Person`.`id`'
)
)
));
Behaviors and find types can also define custom finder keys which are passed into find().
Specifying 'fields' for notation 'list':
- If no fields are specified, then 'id' is used for key and 'model->displayField' is used for value.
- If a single field is specified, 'id' is used for key and specified field is used for value.
- If three fields are specified, they are used (in order) for key, value and group.
- Otherwise, first and second fields are used for key and value. Note: find(list) + database views have issues with MySQL 5.0. Try upgrading to MySQL 5.1 if you have issues with database views.
- Parameters:
-
-
string $type optional 'first'
Type of find operation (all / first / count / neighbors / list / threaded)
-
array $query optional array ( )
Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks)
-
- Method defined in:
- Cake/Model/Model.php on line 2654
- Return
array Array of records
- Link
- http://book.cakephp.org/2.0/en/models/deleting-data.html#deleteall
_findCount
topHandles the before/after filter logic for find('count') operations. Only called by Model::find().
- Parameters:
-
-
string $state required
Either "before" or "after"
-
array $query required
Either "before" or "after"
-
array $results optional array ( )
Either "before" or "after"
-
- Method defined in:
- Cake/Model/Model.php on line 2758
- Return
integer The number of records found, or false
- See
_findFirst
topHandles the before/after filter logic for find('first') operations. Only called by Model::find().
- Parameters:
-
-
string $state required
Either "before" or "after"
-
array $query required
Either "before" or "after"
-
array $results optional array ( )
Either "before" or "after"
-
- Method defined in:
- Cake/Model/Model.php on line 2737
- Return
array
- See
_findList
topHandles the before/after filter logic for find('list') operations. Only called by Model::find().
- Parameters:
-
-
string $state required
Either "before" or "after"
-
array $query required
Either "before" or "after"
-
array $results optional array ( )
Either "before" or "after"
-
- Method defined in:
- Cake/Model/Model.php on line 2796
- Return
array Key/value pairs of primary keys/display field values of all records found
- See
_findNeighbors
topDetects the previous field's value, then uses logic to find the 'wrapping' rows and return them.
- Parameters:
-
-
string $state required
Either "before" or "after"
-
mixed $query required
Either "before" or "after"
-
array $results optional array ( )
Either "before" or "after"
-
- Method defined in:
- Cake/Model/Model.php on line 2854
- Return
array
_findThreaded
topIn the event of ambiguous results returned (multiple top level results, with different parent_ids) top level results with different parent_ids to the first result will be dropped
- Parameters:
-
-
mixed $state required
-
mixed $query required
-
array $results optional array ( )
-
- Method defined in:
- Cake/Model/Model.php on line 2911
- Return
array Threaded results
_generateAssociation
topBuild an array-based association from string.
- Parameters:
-
-
string $type required
'belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'
-
string $assocKey required
'belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'
-
- Method defined in:
- Cake/Model/Model.php on line 1024
- Return
void
__get
topReturns the value of the requested variable if it can be set by __isset()
- Parameters:
-
-
string $name required
variable requested for it's value or reference
-
- Method defined in:
- Cake/Model/Model.php on line 852
- Return
mixed value of requested variable if it is set
getAffectedRows
topReturns the number of rows affected by the last query.
- Method defined in:
- Cake/Model/Model.php on line 3365
- Return
integer Number of rows
getAssociated
topGets all the models with which this model is associated.
- Parameters:
-
-
string $type optional NULL
Only result associations of this type
-
- Method defined in:
- Cake/Model/Model.php on line 3428
- Return
array Associations
getColumnType
topReturns the column type of a column in the model.
- Parameters:
-
-
string $column required
The name of the model column
-
- Method defined in:
- Cake/Model/Model.php on line 1317
- Return
string Column type
getColumnTypes
topReturns an associative array of field names and column types.
- Method defined in:
- Cake/Model/Model.php on line 1299
- Return
array Field types indexed by field name
getDataSource
topGets the DataSource to which this model is bound.
- Method defined in:
- Cake/Model/Model.php on line 3405
- Return
DataSource A DataSource object
getEventManager
topReturns the CakeEventManager manager instance that is handling any callbacks. You can use this instance to register any new listeners or callbacks to the model events, or create your own events and trigger them at will.
- Method defined in:
- Cake/Model/Model.php on line 753
- Return
CakeEventManager
getID
topReturns the current record's ID
- Parameters:
-
-
integer $list optional 0
Index on which the composed ID is located
-
- Method defined in:
- Cake/Model/Model.php on line 3305
- Return
mixed The ID of the current record, false if no ID
getInsertID
topReturns the ID of the last record this model inserted.
- Method defined in:
- Cake/Model/Model.php on line 3337
- Return
mixed Last inserted ID
getLastInsertID
topReturns the ID of the last record this model inserted.
- Method defined in:
- Cake/Model/Model.php on line 3328
- Return
mixed Last inserted ID
getNumRows
topReturns the number of rows returned from the last query.
- Method defined in:
- Cake/Model/Model.php on line 3356
- Return
integer Number of rows
getVirtualField
topReturns the expression for a model virtual field
- Parameters:
-
-
string $field optional NULL
Name of field to look for
-
- Method defined in:
- Cake/Model/Model.php on line 1420
- Return
mixed If $field is string expression bound to virtual field $field If $field is null, returns an array of all model virtual fields or false if none $field exist.
hasAny
topReturns true if a record that meets given conditions exists.
- Parameters:
-
-
array $conditions optional NULL
SQL conditions array
-
- Method defined in:
- Cake/Model/Model.php on line 2597
- Return
boolean True if such a record exists
hasField
topReturns true if the supplied field exists in the model's database table.
- Parameters:
-
-
mixed $name required
Name of field to look for, or an array of names
-
boolean $checkVirtual optional false
checks if the field is declared as virtual
-
- Method defined in:
- Cake/Model/Model.php on line 1347
- Return
mixed If $name is a string, returns a boolean indicating whether the field exists. If $name is an array of field names, returns the first field that exists, or false if none exist.
hasMethod
topCheck that a method is callable on a model. This will check both the model's own methods, its inherited methods and methods that could be callable through behaviors.
- Parameters:
-
-
string $method required
The method to be called.
-
- Method defined in:
- Cake/Model/Model.php on line 1380
- Return
boolean True on method being callable.
implementedEvents
topReturns a list of all events that will fire in the model during it's lifecycle. You can override this function to add you own listener callbacks
- Method defined in:
- Cake/Model/Model.php on line 734
- Return
array
invalidate
topMarks a field as invalid, optionally setting the name of validation rule (in case of multiple validation for field) that was broken.
- Parameters:
-
-
string $field required
The name of the field to invalidate
-
mixed $value optional true
Name of validation rule that was not failed, or validation message to be returned. If no validation key is provided, defaults to true.
-
- Method defined in:
- Cake/Model/Model.php on line 3254
- Return
void
invalidFields
topReturns an array of fields that have failed validation. On the current model.
- Parameters:
-
-
string $options optional array ( )
An optional array of custom options to be made available in the beforeValidate callback
-
- Method defined in:
- Cake/Model/Model.php on line 3050
- Return
array Array of invalid fields
- See
isForeignKey
topReturns true if given field name is a foreign key in this model.
- Parameters:
-
-
string $field required
Returns true if the input string ends in "_id"
-
- Method defined in:
- Cake/Model/Model.php on line 3267
- Return
boolean True if the field is a foreign key listed in the belongsTo array.
__isset
topHandles the lazy loading of model associations by looking in the association arrays for the requested variable
- Parameters:
-
-
string $name required
variable tested for existence in class
-
- Method defined in:
- Cake/Model/Model.php on line 785
- Return
boolean true if the variable exists (if is a not loaded model association it will be created), false otherwise
isUnique
topReturns false if any fields passed match any (by default, all if $or = false) of their matching values.
- Parameters:
-
-
array $fields required
Field/value pairs to search (if no values specified, they are pulled from $this->data)
-
boolean $or optional true
If false, all fields specified must match in order for a false return value
-
- Method defined in:
- Cake/Model/Model.php on line 2975
- Return
boolean False if any records matching any fields are found
isVirtualField
topReturns true if the supplied field is a model Virtual Field
- Parameters:
-
-
string $field required
Name of field to look for
-
- Method defined in:
- Cake/Model/Model.php on line 1396
- Return
boolean indicating whether the field exists as a model virtual field.
joinModel
topGets the name and fields to be used by a join model. This allows specifying join fields in the association definition.
- Parameters:
-
-
string|array $assoc required
The model to be joined
-
array $keys optional array ( )
Any join keys which must be merged with the keys queried
-
- Method defined in:
- Cake/Model/Model.php on line 3473
- Return
array
log
topConvenience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.
- Parameters:
-
-
string $msg required
Log message
-
integer $type optional 2
Error type constant. Defined in app/Config/core.php.
-
- Method defined in:
- Cake/Core/Object.php on line 149
- Return
boolean Success of log write
_mergeVars
topMerges this objects $property with the property in $class' definition. This classes value for the property will be merged on top of $class'
This provides some of the DRY magic CakePHP provides. If you want to shut it off, redefine this method as an empty function.
- Parameters:
-
-
array $properties required
The name of the properties to merge.
-
string $class required
The class to merge the property with.
-
boolean $normalize optional true
Set to true to run the properties through Set::normalize() before merging.
-
- Method defined in:
- Cake/Core/Object.php on line 187
- Return
void
node
topRetrieves the Aro/Aco node for this model
- Parameters:
-
-
mixed $ref optional NULL
Array with 'model' and 'foreign_key', model object, or string value
-
- Method defined in:
- Cake/Model/AclNode.php on line 61
- Return
array Node found in database
- Throws
CakeException when binding to a model that doesn't exist.
_normalizeXmlData
topNormalize Xml::toArray() to use in Model::save()
- Parameters:
-
-
array $xml required
XML as array
-
- Method defined in:
- Cake/Model/Model.php on line 1169
- Return
array
onError
topCalled when a DataSource-level error occurs.
- Method defined in:
- Cake/Model/Model.php on line 3573
- Return
void
- Link
- http://book.cakephp.org/2.0/en/models/callback-methods.html#onerror
_prepareUpdateFields
topHelper method for Model::updateCounterCache(). Checks the fields to be updated for
- Parameters:
-
-
array $data required
The fields of the record that will be updated
-
- Method defined in:
- Cake/Model/Model.php on line 1943
- Return
array Returns updated foreign key values, along with an 'old' key containing the old values, or empty if no foreign keys are updated.
query
topReturns a resultset for a given SQL statement. Custom SQL queries should be performed with this method.
- Parameters:
-
-
$sql required
-
- Method defined in:
- Cake/Model/Model.php on line 3017
- Return
mixed Resultset array or boolean indicating success / failure depending on the query executed
- Link
- http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#model-query
read
topReturns a list of fields from the database, and sets the current model data (Model::$data) with the record found.
- Parameters:
-
-
mixed $fields optional NULL
String of single field name, or an array of field names.
-
mixed $id optional NULL
The ID of the record to read
-
- Method defined in:
- Cake/Model/Model.php on line 1474
- Return
array Array of database fields, or false if not found
- Link
- http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#model-read
requestAction
topCalls a controller's method from any location. Can be used to connect controllers together or tie plugins into a main application. requestAction can be used to return rendered views or fetch the return value from controller actions.
Under the hood this method uses Router::reverse() to convert the $url parameter into a string URL. You should use URL formats that are compatible with Router::reverse()
Passing POST and GET data
POST and GET data can be simulated in requestAction. Use $extra['url'] for
GET data. The $extra['data'] parameter allows POST data simulation.
- Parameters:
-
-
mixed $url required
String or array-based url. Unlike other url arrays in CakePHP, this url will not automatically handle passed and named arguments in the $url parameter.
-
array $extra optional array ( )
if array includes the key "return" it sets the AutoRender to true. Can also be used to submit GET/POST data, and named/passed arguments.
-
- Method defined in:
- Cake/Core/Object.php on line 66
- Return
mixed Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
resetAssociations
topThis resets the association arrays for the model back to those originally defined in the model. Normally called at the end of each call to Model::find()
- Method defined in:
- Cake/Model/Model.php on line 2947
- Return
boolean Success
save
topSaves model data (based on white-list, if supplied) to the database. By default, validation occurs before save.
- Parameters:
-
-
array $data optional NULL
Data to save.
-
mixed $validate optional true
Either a boolean, or an array. If a boolean, indicates whether or not to validate before saving. If an array, allows control of validate, callbacks, and fieldList
-
array $fieldList optional array ( )
List of fields to allow to be written
-
- Method defined in:
- Cake/Model/Model.php on line 1572
- Return
mixed On success Model::$data if its not empty or true, false on failure
- Link
- http://book.cakephp.org/2.0/en/models/saving-your-data.html
saveAll
topBackwards compatible passthrough method for: saveMany(), validateMany(), saveAssociated() and validateAssociated()
Saves multiple individual records for a single model; Also works with a single record, as well as all its associated records.
Options
- validate: Set to false to disable validation, true to validate each record before saving, 'first' to validate all records before any are saved (default), or 'only' to only validate the records, but not save them.
- atomic: If true (default), will attempt to save all records in a single transaction. Should be set to false if database/table does not support transactions.
- fieldList: Equivalent to the $fieldList parameter in Model::save(). It should be an associate array with model name as key and array of fields as value. Eg. {{{ array( 'SomeModel' => array('field'), 'AssociatedModel' => array('field', 'otherfield') ) }}}
- deep: see saveMany/saveAssociated
- Parameters:
-
-
array $data optional NULL
Record data to save. This can be either a numerically-indexed array (for saving multiple records of the same type), or an array indexed by association name.
-
array $options optional array ( )
Options to use when saving record data, See $options above.
-
- Method defined in:
- Cake/Model/Model.php on line 1996
- Return
mixed If atomic: True on success, or false on failure. Otherwise: array similar to the $data array passed, but values are set to true/false depending on whether each record saved successfully.
- Link
saveAssociated
topSaves a single record, as well as all its directly associated records.
Options
validateSet tofalseto disable validation,trueto validate each record before saving, 'first' to validate all records before any are saved(default),atomicIf true (default), will attempt to save all records in a single transaction. Should be set to false if database/table does not support transactions.- fieldList: Equivalent to the $fieldList parameter in Model::save(). It should be an associate array with model name as key and array of fields as value. Eg. {{{ array( 'SomeModel' => array('field'), 'AssociatedModel' => array('field', 'otherfield') ) }}}
- deep: If set to true, not only directly associated data is saved, but deeper nested associated data as well.
- Parameters:
-
-
array $data optional NULL
Record data to save. This should be an array indexed by association name.
-
array $options optional array ( )
Options to use when saving record data, See $options above.
-
- Method defined in:
- Cake/Model/Model.php on line 2163
- Return
mixed If atomic: True on success, or false on failure. Otherwise: array similar to the $data array passed, but values are set to true/false depending on whether each record saved successfully.
- Link
- http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveassociated-array-data-null-array-options-array
saveField
topSaves the value of a single field to the database, based on the current model ID.
- Parameters:
-
-
string $name required
Name of the table field
-
mixed $value required
Value of the field
-
array $validate optional false
See $options param in Model::save(). Does not respect 'fieldList' key if passed
-
- Method defined in:
- Cake/Model/Model.php on line 1548
saveMany
topSaves multiple individual records for a single model
Options
- validate: Set to false to disable validation, true to validate each record before saving, 'first' to validate all records before any are saved (default),
- atomic: If true (default), will attempt to save all records in a single transaction. Should be set to false if database/table does not support transactions.
- fieldList: Equivalent to the $fieldList parameter in Model::save()
- deep: If set to true, all associated data will be saved as well.
- Parameters:
-
-
array $data optional NULL
Record data to save. This should be a numerically-indexed array
-
array $options optional array ( )
Options to use when saving record data, See $options above.
-
- Method defined in:
- Cake/Model/Model.php on line 2029
- Return
mixed If atomic: True on success, or false on failure. Otherwise: array similar to the $data array passed, but values are set to true/false depending on whether each record saved successfully.
- Link
- http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-savemany-array-data-null-array-options-array
_saveMulti
topSaves model hasAndBelongsToMany data to the database.
- Parameters:
-
-
array $joined required
Data to save
-
mixed $id required
ID of record in this model
-
DataSource $db required
ID of record in this model
-
- Method defined in:
- Cake/Model/Model.php on line 1751
- Return
void
schema
topReturns an array of table metadata (column names and types) from the database. $field => keys(type, null, default, key, length, extra)
- Parameters:
-
-
mixed $field optional false
Set to true to reload schema, or a string to return a specific field
-
- Method defined in:
- Cake/Model/Model.php on line 1274
- Return
array Array of table metadata
set
topThis function does two things:
- it scans the array $one for the primary key, and if that's found, it sets the current id to the value of $one[id]. For all other keys than 'id' the keys and values of $one are copied to the 'data' property of this object.
- Returns an array with all of $one's keys and values. (Alternative indata: two strings, which are mangled to a one-item, two-dimensional array using $one for a key and $two as its value.)
- Parameters:
-
-
mixed $one required
Array or string of data
-
string $two optional NULL
Value string for the alternative indata method
-
- Method defined in:
- Cake/Model/Model.php on line 1117
- Return
array Data with all of $one's keys and values
- Link
- http://book.cakephp.org/2.0/en/models/saving-your-data.html
_set
topAllows setting of multiple properties of the object in a single line of code. Will only set properties that are part of a class declaration.
- Parameters:
-
-
array $properties optional array ( )
An associative array containing properties and corresponding values.
-
- Method defined in:
- Cake/Core/Object.php on line 164
- Return
void
setDataSource
topSets the DataSource to which this model is bound.
- Parameters:
-
-
string $dataSource optional NULL
The name of the DataSource, as defined in app/Config/database.php
-
- Method defined in:
- Cake/Model/Model.php on line 3376
- Return
void
- Throws
MissingConnectionException
setInsertID
topSets the ID of the last record this model inserted
- Parameters:
-
-
mixed $id required
Last inserted ID
-
- Method defined in:
- Cake/Model/Model.php on line 3347
- Return
void
setSource
topSets a custom table for your controller class. Used by your controller to select a database table.
- Parameters:
-
-
string $tableName required
Name of the custom table
-
- Method defined in:
- Cake/Model/Model.php on line 1082
- Throws
MissingTableException when database table $tableName is not found on data source
- Return
void
_stop
topStop execution of the current script. Wraps exit() making testing easier.
- Parameters:
-
-
integer|string $status optional 0
see http://php.net/exit for values
-
- Method defined in:
- Cake/Core/Object.php on line 137
- Return
void
toString
topObject-to-string conversion. Each class can override this method as necessary.
- Method defined in:
- Cake/Core/Object.php on line 41
- Return
string The name of this class
unbindModel
topTurn off associations on the fly.
If $reset is false, association will not be reset to the originals defined in the model
Example: Turn off the associated Model Support request, to temporarily lighten the User model:
$this->User->unbindModel( array('hasMany' => array('Supportrequest')) );
unbound models that are not made permanent will reset with the next call to Model::find()
- Parameters:
-
-
array $params required
Set of bindings to unbind (indexed by binding type)
-
boolean $reset optional true
Set to false to make the unbinding permanent
-
- Method defined in:
- Cake/Model/Model.php on line 930
updateAll
topUpdates multiple model records based on a set of conditions.
- Parameters:
-
-
array $fields required
Set of fields and values, indexed by fields. Fields are treated as SQL snippets, to insert literal values manually escape your data.
-
mixed $conditions optional true
Conditions to match, true for all records
-
- Method defined in:
- Cake/Model/Model.php on line 2367
- Return
boolean True on success, false on failure
- Link
- http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-updateall-array-fields-array-conditions
updateCounterCache
topUpdates the counter cache of belongsTo associations after a save or delete operation
- Parameters:
-
-
array $keys optional array ( )
Optional foreign key data, defaults to the information $this->data
-
boolean $created optional false
True if a new record was created, otherwise only associations with 'counterScope' defined get updated
-
- Method defined in:
- Cake/Model/Model.php on line 1874
- Return
void
validateAssociated
topValidates a single record, as well as all its directly associated records.
Options
- atomic: If true (default), returns boolean. If false returns array.
- fieldList: Equivalent to the $fieldList parameter in Model::save()
- deep: If set to true, not only directly associated data , but deeper nested associated data is validated as well.
- Parameters:
-
-
array $data required
Record data to validate. This should be an array indexed by association name.
-
array $options optional array ( )
Options to use when validating record data (see above), See also $options of validates().
-
- Method defined in:
- Cake/Model/Model.php on line 2308
- Return
array|boolean If atomic: True on success, or false on failure. Otherwise: array similar to the $data array passed, but values are set to true/false depending on whether each record validated successfully.
validateMany
topValidates multiple individual records for a single model
Options
- atomic: If true (default), returns boolean. If false returns array.
- fieldList: Equivalent to the $fieldList parameter in Model::save()
- deep: If set to true, all associated data will be validated as well.
- Parameters:
-
-
array $data required
Record data to validate. This should be a numerically-indexed array
-
array $options optional array ( )
Options to use when validating record data (see above), See also $options of validates().
-
- Method defined in:
- Cake/Model/Model.php on line 2110
- Return
boolean True on success, or false on failure.
mixed If atomic: True on success, or false on failure. Otherwise: array similar to the $data array passed, but values are set to true/false depending on whether each record validated successfully.
validates
topReturns true if all fields pass validation. Will validate hasAndBelongsToMany associations that use the 'with' key as well. Since _saveMulti is incapable of exiting a save operation.
Will validate the currently set data. Use Model::set() or Model::create() to set the active data.
- Parameters:
-
-
array $options optional array ( )
An optional array of custom options to be made available in the beforeValidate callback
-
- Method defined in:
- Cake/Model/Model.php on line 3032
- Return
boolean True if there are no errors
_validateWithModels
topRuns validation for hasAndBelongsToMany associations that have 'with' keys set. And data in the set() data set.
- Parameters:
-
-
array $options required
Array of options to use on Validation of with models
-
- Method defined in:
- Cake/Model/Model.php on line 3216
- Return
boolean Failure of validation on with models.
- See
