CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 1.3 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 1.3
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Classes

  • AclBase
  • AclBehavior
  • AclComponent
  • AclNode
  • AclShell
  • Aco
  • AcoAction
  • AjaxHelper
  • ApcEngine
  • ApiShell
  • App
  • AppController
  • AppHelper
  • AppModel
  • Aro
  • AuthComponent
  • BakeShell
  • BakeTask
  • BehaviorCollection
  • Cache
  • CacheEngine
  • CacheHelper
  • CakeErrorController
  • CakeLog
  • CakeRoute
  • CakeSchema
  • CakeSession
  • CakeSocket
  • ClassRegistry
  • Component
  • Configure
  • ConnectionManager
  • ConsoleShell
  • ContainableBehavior
  • Controller
  • ControllerTask
  • CookieComponent
  • DataSource
  • DbAcl
  • DbConfigTask
  • DboMssql
  • DboMysql
  • DboMysqlBase
  • DboMysqli
  • DboOracle
  • DboPostgres
  • DboSource
  • DboSqlite
  • Debugger
  • EmailComponent
  • ErrorHandler
  • ExtractTask
  • File
  • FileEngine
  • FileLog
  • FixtureTask
  • Folder
  • FormHelper
  • Helper
  • HtmlHelper
  • HttpSocket
  • I18n
  • I18nModel
  • I18nShell
  • Inflector
  • IniAcl
  • JavascriptHelper
  • JqueryEngineHelper
  • JsBaseEngineHelper
  • JsHelper
  • L10n
  • MagicDb
  • MagicFileResource
  • MediaView
  • MemcacheEngine
  • Model
  • ModelBehavior
  • ModelTask
  • MootoolsEngineHelper
  • Multibyte
  • NumberHelper
  • Object
  • Overloadable
  • Overloadable2
  • PagesController
  • PaginatorHelper
  • Permission
  • PluginShortRoute
  • PluginTask
  • ProjectTask
  • PrototypeEngineHelper
  • RequestHandlerComponent
  • Router
  • RssHelper
  • Sanitize
  • Scaffold
  • ScaffoldView
  • SchemaShell
  • Security
  • SecurityComponent
  • SessionComponent
  • SessionHelper
  • Set
  • Shell
  • String
  • TemplateTask
  • TestSuiteShell
  • TestTask
  • TextHelper
  • ThemeView
  • TimeHelper
  • TranslateBehavior
  • TreeBehavior
  • Validation
  • View
  • ViewTask
  • XcacheEngine
  • Xml
  • XmlElement
  • XmlHelper
  • XmlManager
  • XmlNode
  • XmlTextNode

Functions

  • mb_encode_mimeheader
  • mb_stripos
  • mb_stristr
  • mb_strlen
  • mb_strpos
  • mb_strrchr
  • mb_strrichr
  • mb_strripos
  • mb_strrpos
  • mb_strstr
  • mb_strtolower
  • mb_strtoupper
  • mb_substr
  • mb_substr_count

Class AclNode

ACL Node

Object
Extended by Overloadable
Extended by Model
Extended by AppModel
Extended by AclNode
Direct Subclasses
  • Aco
  • Aro
Package: cake\cake\libs\model
Copyright: Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: License (http://www.opensource.org/licenses/mit-license.php)
Location: model/db_acl.php

Properties summary

  • $actsAs public
    array
    ACL models use the Tree behavior
  • $cacheQueries public
    boolean
    Explicitly disable in-memory query caching for ACL models

Inherited Properties

  • Behaviors, __affectedRows, __associationKeys, __associations, __backAssociation, __insertID, __numRows, __safeUpdateMode, _findMethods, _schema, alias, belongsTo, cacheSources, data, displayField, findQueryType, hasAndBelongsToMany, hasMany, hasOne, id, logTransactions, name, order, primaryKey, recursive, table, tablePrefix, tableToModel, useDbConfig, useTable, validate, validationErrors, virtualFields, whitelist

Method Summary

  • __construct() public
    Constructor
  • node() public
    Retrieves the Aro/Aco node for this model

Method Detail

__construct() public ¶

__construct( )

Constructor

Overrides
Model::__construct()

node() public ¶

node( mixed $ref = null )

Retrieves the Aro/Aco node for this model

Parameters
mixed $ref optional null
Array with 'model' and 'foreign_key', model object, or string value
Returns
array
Node found in database

Methods inherited from Model

__collectForeignKeys() public ¶

__collectForeignKeys( $type = 'belongsTo' )

Collects foreign keys from associations.

Returns
array

__constructLinkedModel() public deprecated ¶

__constructLinkedModel( string $assoc , string $className = null )

Private helper method to create associated models of a given class.

Deprecated

$this->$className use $this->$assoc instead. $assoc is the 'key' in the associations array; examples: var $hasMany = array('Assoc' => array('className' => 'ModelName')); usage: $this->Assoc->modelMethods();

            var $hasMany = array('ModelName');
                usage: $this->ModelName->modelMethods();

Parameters
string $assoc
Association name
string $className optional null
Class name

__createLinks() public ¶

__createLinks( )

Create a set of associations.

__filterResults() public ¶

__filterResults( array $results , boolean $primary = true )

Passes query results through model and behavior afterFilter() methods.

Parameters
array $results
to filter
boolean $primary optional true
If this is the primary model results (results from model where the find operation was performed)
Returns
array
Set of filtered results

__generateAssociation() public ¶

__generateAssociation( string $type )

Build an array-based association from string.

Parameters
string $type
'belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'

__save() public ¶

__save( $data , $options )

Private helper method used by saveAll.

Returns
boolean
Success
See
Model::saveAll()

__saveMulti() public ¶

__saveMulti( array $joined , mixed $id , $db )

Saves model hasAndBelongsToMany data to the database.

Parameters
array $joined
Data to save
mixed $id
ID of record in this model
$db

__sleep() public ¶

__sleep( )

Called when serializing a model.

Returns
array
Set of object variable names this model has

__validateWithModels() public ¶

__validateWithModels( array $options )

Runs validation for hasAndBelongsToMany associations that have 'with' keys set. And data in the set() data set.

Parameters
array $options
Array of options to use on Valdation of with models
Returns
boolean
Failure of validation on with models.
See
Model::validates()

__wakeup() public ¶

__wakeup( )

Called when de-serializing a model.

_clearCache() public ¶

_clearCache( string $type = null )

Private method. Clears 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

Returns
boolean
true on delete

_deleteDependent() public ¶

_deleteDependent( string $id , boolean $cascade )

Cascades model deletes through associated hasMany and hasOne child records.

Parameters
string $id
ID of record that was deleted
boolean $cascade
Set to true to delete records that depend on this record

_deleteLinks() public ¶

_deleteLinks( string $id )

Cascades model deletes through HABTM join keys.

Parameters
string $id
ID of record that was deleted

_findCount() public ¶

_findCount( string $state , array $query , array $results = array() )

Handles the before/after filter logic for find('count') operations. Only called by Model::find().

Parameters
string $state
Either "before" or "after"
array $query
array $results optional array()
$data
Returns
integer
The number of records found, or false
See
Model::find()

_findFirst() public ¶

_findFirst( string $state , array $query , array $results = array() )

Handles the before/after filter logic for find('first') operations. Only called by Model::find().

Parameters
string $state
Either "before" or "after"
array $query
array $results optional array()
$data
Returns
array
See
Model::find()

_findList() public ¶

_findList( string $state , array $query , array $results = array() )

Handles the before/after filter logic for find('list') operations. Only called by Model::find().

Parameters
string $state
Either "before" or "after"
array $query
array $results optional array()
$data
Returns
array
Key/value pairs of primary keys/display field values of all records found
See
Model::find()

_findNeighbors() public ¶

_findNeighbors( string $state , mixed $query , array $results = array() )

Detects the previous field's value, then uses logic to find the 'wrapping' rows and return them.

Parameters
string $state
Either "before" or "after"
mixed $query
array $results optional array()
Returns
array

_findThreaded() public ¶

_findThreaded( mixed $state , mixed $query , array $results = array() )

In 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
mixed $query
array $results optional array()
Returns
array
Threaded results

_prepareUpdateFields() public ¶

_prepareUpdateFields( array $data )

Helper method for Model::updateCounterCache(). Checks the fields to be updated for

Parameters
array $data
The fields of the record that will be updated
Returns
array

Returns updated foreign key values, along with an 'old' key containing the old values, or empty if no foreign keys are updated.


afterDelete() public ¶

afterDelete( )

Called after every deletion operation.

Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Callback-Methods#afterDelete-1055

afterFind() public ¶

afterFind( mixed $results , boolean $primary = false )

Called after each find operation. Can be used to modify any results returned by find(). Return value should be the (modified) results.

Parameters
mixed $results
The results of the find operation
boolean $primary optional false
Whether this model is being queried directly (vs. being queried as an association)
Returns
mixed
Result of the find operation
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Callback-Methods#afterFind-1050

afterSave() public ¶

afterSave( boolean $created )

Called after each successful save operation.

Parameters
boolean $created
True if this save created a new record
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Callback-Methods#afterSave-1053

beforeDelete() public ¶

beforeDelete( boolean $cascade = true )

Called before every deletion operation.

Parameters
boolean $cascade optional true
If true records that depend on this record will also be deleted
Returns
boolean
True if the operation should continue, false if it should abort
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Callback-Methods#beforeDelete-1054

beforeFind() public ¶

beforeFind( array $queryData )

Called before each find operation. Return false if you want to halt the find call, otherwise return the (modified) query data.

Parameters
array $queryData
Data used to execute this query, i.e. conditions, order, etc.
Returns
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/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Callback-Methods#beforeFind-1049

beforeSave() public ¶

beforeSave( $options = array() )

Called before each save operation, after validation. Return a non-true result to halt the save.

Returns
boolean
True if the operation should continue, false if it should abort
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Callback-Methods#beforeSave-1052

beforeValidate() public ¶

beforeValidate( $options = array() )

Called during validation operations, before validation. Please note that custom validation rules can be defined in $validate.

Parameters
$options optional array()
Options passed from model::save(), see $options of model::save().
Returns
boolean
True if validate operation should continue, false to abort
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Callback-Methods#beforeValidate-1051

bindModel() public ¶

bindModel( array $params , boolean $reset = true )

Bind 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
Set of bindings (indexed by binding type)
boolean $reset optional true
Set to false to make the binding permanent
Returns
boolean
Success
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Creating-and-Destroying-Associations-on-the-Fly

call__() public ¶

call__( string $method , array $params )

Handles custom method calls, like findBy for DB models, and custom RPC calls for remote data sources.

Parameters
string $method
Name of method to call.
array $params
Parameters for the method.
Returns
mixed
Whatever is returned by called method

create() public ¶

create( mixed $data = array() , boolean $filterKey = false )

Initializes 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
Returns
array
The current Model::data; after merging $data and/or defaults from database
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Saving-Your-Data

deconstruct() public ¶

deconstruct( string $field , mixed $data )

Deconstructs a complex data type (array or object) into a single field value.

Parameters
string $field
The name of the field to be deconstructed
mixed $data
An array or object to be deconstructed into a field
Returns
mixed
The resulting data that should be assigned to a field

delete() public ¶

delete( mixed $id = null , boolean $cascade = true )

Removes 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
Returns
boolean
True on success
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#delete

deleteAll() public ¶

deleteAll( mixed $conditions , boolean $cascade = true , boolean $callbacks = false )

Deletes multiple model records based on a set of conditions.

Parameters
mixed $conditions
Conditions to match
boolean $cascade optional true
Set to true to delete records that depend on this record
boolean $callbacks optional false
Run callbacks
Returns
boolean
True on success, false on failure
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#deleteAll

escapeField() public ¶

escapeField( string $field = null , string $alias = null )

Escapes 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)
Returns
string
The name of the escaped field for this Model (i.e. id becomes Post.id).

exists() public ¶

exists( )

Returns true if a record with the currently set ID exists.

Internally calls Model::getID() to obtain the current record ID to verify, and then performs a Model::find('count') on the currently configured datasource to ascertain the existence of the record in persistent storage.

Returns
boolean
True if such a record exists

field() public ¶

field( string $name , array $conditions = null , string $order = null )

Returns the contents of a single field given the supplied conditions, in the supplied order.

Parameters
string $name
Name of field to get
array $conditions optional null
SQL conditions (defaults to NULL)
string $order optional null
SQL ORDER BY fragment
Returns
string
field contents, or false if not found
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Retrieving-Your-Data#field-1028

find() public ¶

find( array $conditions = null , mixed $fields = array() , string $order = null , integer $recursive = null )

Queries the datasource and returns a result set array.

Also used to perform new-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 new-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
array $conditions optional null

SQL conditions array, or type of find operation (all / first / count / neighbors / list / threaded)

mixed $fields optional array()

Either a single string of a field name, or an array of field names, or options for matching

string $order optional null
SQL ORDER BY conditions (e.g. "price DESC" or "name ASC")
integer $recursive optional null
The number of levels deep to fetch associated records
Returns
array
Array of records
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#find

getAffectedRows() public ¶

getAffectedRows( )

Returns the number of rows affected by the last query.

Returns
integer
Number of rows

getAssociated() public ¶

getAssociated( string $type = null )

Gets all the models with which this model is associated.

Parameters
string $type optional null
Only result associations of this type
Returns
array
Associations

getColumnType() public ¶

getColumnType( string $column )

Returns the column type of a column in the model.

Parameters
string $column
The name of the model column
Returns
string
Column type

getColumnTypes() public ¶

getColumnTypes( )

Returns an associative array of field names and column types.

Returns
array
Field types indexed by field name

getDataSource() public ¶

getDataSource( )

Gets the DataSource to which this model is bound. Not safe for use with some versions of PHP4, because this class is overloaded.

Returns
object
A DataSource object

getID() public ¶

getID( integer $list = 0 )

Returns the current record's ID

Parameters
integer $list optional 0
Index on which the composed ID is located
Returns
mixed
The ID of the current record, false if no ID

getInsertID() public ¶

getInsertID( )

Returns the ID of the last record this model inserted.

Returns
mixed
Last inserted ID

getLastInsertID() public ¶

getLastInsertID( )

Returns the ID of the last record this model inserted.

Returns
mixed
Last inserted ID

getNumRows() public ¶

getNumRows( )

Returns the number of rows returned from the last query.

Returns
integer
Number of rows

getVirtualField() public ¶

getVirtualField( mixed $field = null )

Returns the expression for a model virtual field

Parameters
mixed $field optional null
$name Name of field to look for
Returns
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() public ¶

hasAny( array $conditions = null )

Returns true if a record that meets given conditions exists.

Parameters
array $conditions optional null
SQL conditions array
Returns
boolean
True if such a record exists

hasField() public ¶

hasField( mixed $name , boolean $checkVirtual = false )

Returns true if the supplied field exists in the model's database table.

Parameters
mixed $name
Name of field to look for, or an array of names
boolean $checkVirtual optional false
checks if the field is declared as virtual
Returns
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.


invalidFields() public ¶

invalidFields( string $options = array() )

Returns 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
Returns
array
Array of invalid fields
See
Model::validates()
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Validating-Data-from-the-Controller

invalidate() public ¶

invalidate( string $field , mixed $value = true )

Marks a field as invalid, optionally setting the name of validation rule (in case of multiple validation for field) that was broken.

Parameters
string $field
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.

isForeignKey() public ¶

isForeignKey( string $field )

Returns true if given field name is a foreign key in this model.

Parameters
string $field
Returns true if the input string ends in "_id"
Returns
boolean
True if the field is a foreign key listed in the belongsTo array.

isUnique() public ¶

isUnique( array $fields , boolean $or = true )

Returns false if any fields passed match any (by default, all if $or = false) of their matching values.

Parameters
array $fields
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
Returns
boolean
False if any records matching any fields are found

isVirtualField() public ¶

isVirtualField( mixed $field )

Returns true if the supplied field is a model Virtual Field

Parameters
mixed $field
$name Name of field to look for
Returns
boolean
indicating whether the field exists as a model virtual field.

joinModel() public ¶

joinModel( object $assoc , mixed $keys = array() , array $keys ,… )

Gets the name and fields to be used by a join model. This allows specifying join fields in the association definition.

Parameters
object $assoc
$model The model to be joined
mixed $keys optional array()
$with The 'with' key of the model association
array $keys ,…
Any join keys which must be merged with the keys queried
Returns
array

onError() public ¶

onError( )

Called when a DataSource-level error occurs.

Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Callback-Methods#onError-1056

query() public ¶

query( string $sql ,… )

Returns a resultset for a given SQL statement. Custom SQL queries should be performed with this method.

Parameters
string $sql ,…
SQL statement
Returns
array
Resultset
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#query

read() public ¶

read( mixed $fields = null , mixed $id = null )

Returns 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 fieldname, or an array of fieldnames.
mixed $id optional null
The ID of the record to read
Returns
array
Array of database fields, or false if not found
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Retrieving-Your-Data#read-1029

resetAssociations() public ¶

resetAssociations( )

This 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()

Returns
boolean
Success

save() public ¶

save( array $data = null , mixed $validate = true , array $fieldList = array() )

Saves 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
Returns
mixed
On success Model::$data if its not empty or true, false on failure
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Saving-Your-Data

saveAll() public ¶

saveAll( array $data = null , array $options = array() )

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()
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.
Returns
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/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Saving-Related-Model-Data-hasOne-hasMany-belongsTo
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Saving-Your-Data

saveField() public ¶

saveField( string $name , mixed $value , array $validate = false )

Saves the value of a single field to the database, based on the current model ID.

Parameters
string $name
Name of the table field
mixed $value
Value of the field
array $validate optional false
See $options param in Model::save(). Does not respect 'fieldList' key if passed
Returns
boolean
See Model::save()
See
Model::save()
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Saving-Your-Data

schema() public ¶

schema( mixed $field = false )

Returns 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
Returns
array
Array of table metadata

set() public ¶

set( mixed $one , string $two = null )

This function does two things:

  1. 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.
  2. 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
Array or string of data
string $two optional null
Value string for the alternative indata method
Returns
array
Data with all of $one's keys and values
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Saving-Your-Data

setDataSource() public ¶

setDataSource( string $dataSource = null )

Sets 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
Returns
boolean
True on success

setInsertID() public ¶

setInsertID( mixed $id )

Sets the ID of the last record this model inserted

Parameters
mixed $id
inserted ID

setSource() public ¶

setSource( string $tableName )

Sets a custom table for your controller class. Used by your controller to select a database table.

Parameters
string $tableName
Name of the custom table

unbindModel() public ¶

unbindModel( array $params , boolean $reset = true )

Turn 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
Set of bindings to unbind (indexed by binding type)
boolean $reset optional true
Set to false to make the unbinding permanent
Returns
boolean
Success
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Creating-and-Destroying-Associations-on-the-Fly

updateAll() public ¶

updateAll( array $fields , mixed $conditions = true )

Updates multiple model records based on a set of conditions.

Parameters
array $fields

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
Returns
boolean
True on success, false on failure
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Saving-Your-Data

updateCounterCache() public ¶

updateCounterCache( array $keys = array() , boolean $created = false )

Updates 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

validates() public ¶

validates( string $options = array() )

Returns 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
string $options optional array()
An optional array of custom options to be made available in the beforeValidate callback
Returns
boolean
True if there are no errors
Link
http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#Validating-Data-from-the-Controller

Methods inherited from Overloadable

__call() public ¶

__call( string $method , array $params )

Magic method handler.

Parameters
string $method
Method name
array $params
Parameters to send to method
Returns
mixed
Return value from method

overload() public ¶

overload( )

Overload implementation. No need for implementation in PHP5.

Methods inherited from Object

Object() public ¶

Object( )

A hack to support __construct() on PHP 4 Hint: descendant classes have no PHP4 class_name() constructors, so this constructor gets called first and calls the top-layer __construct() which (if present) should call parent::__construct()

Returns
Object

__openPersistent() public ¶

__openPersistent( string $name , string $type = null )

Open the persistent class file for reading Used by Object::_persist()

Parameters
string $name
Name of persisted class
string $type optional null
Type of persistance (e.g: registry)

_persist() public ¶

_persist( string $name , string $return , $object , $type = null )

Checks for a persistent class file, if found file is opened and true returned If file is not found a file is created and false returned If used in other locations of the model you should choose a unique name for the persistent file There are many uses for this method, see manual for examples

Parameters
string $name
name of the class to persist
string $return
$object the object to persist
$object
$type optional null
Returns
boolean
Success

_savePersistent() public ¶

_savePersistent( string $name , object $object )

You should choose a unique name for the persistent file

There are many uses for this method, see manual for examples

Parameters
string $name
name used for object to cache
object $object
the object to persist
Returns
boolean
true on save, throws error if file can not be created

_set() public ¶

_set( array $properties = array() )

Allows 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.

_stop() public ¶

_stop( $status = 0 )

Stop execution of the current script. Wraps exit() making testing easier.

Parameters
$status optional 0
http://php.net/exit for values

cakeError() public ¶

cakeError( string $method , array $messages = array() )

Used to report user friendly errors. If there is a file app/error.php or app/app_error.php this file will be loaded error.php is the AppError class it should extend ErrorHandler class.

Parameters
string $method
Method to be called in the error class (AppError or ErrorHandler classes)
array $messages optional array()
Message that is to be displayed by the error class
Returns
error
message

dispatchMethod() public ¶

dispatchMethod( string $method , array $params = array() )

Calls a method on this object with the given parameters. Provides an OO wrapper for call_user_func_array

Parameters
string $method
Name of the method to call
array $params optional array()
Parameter list to use when calling $method
Returns
mixed
Returns the result of the method call

log() public ¶

log( string $msg , integer $type = LOG_ERROR )

Convience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.

Parameters
string $msg
Log message
integer $type optional LOG_ERROR
Error type constant. Defined in app/config/core.php.
Returns
boolean
Success of log write

requestAction() public ¶

requestAction( mixed $url , array $extra = array() )

Calls 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.

Parameters
mixed $url
String or array-based url.
array $extra optional array()
if array includes the key "return" it sets the AutoRender to true.
Returns
mixed

Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.


toString() public ¶

toString( )

Object-to-string conversion. Each class can override this method as necessary.

Returns
string
The name of this class

Properties detail

$actsAs ¶

public array

ACL models use the Tree behavior

array('Tree' => 'nested')

$cacheQueries ¶

public boolean

Explicitly disable in-memory query caching for ACL models

false
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs