ContainableBehavior Class Info:

Class Declaration:

class ContainableBehavior extends ModelBehavior

File name:
cake/libs/model/behaviors/containable.php
Description:

Behavior to allow for dynamic and atomic manipulation of a Model's associations used for a find call. Most useful for limiting the amount of associations and data returned.

Class Inheritance

ModelBehavior Object

Properties:

Show/Hide parent properties
  • mapMethods array

    Allows the mapping of preg-compatible regular expressions to public or private methods in this class, where the array key is a /-delimited regular expression, and the value is a class method. Similar to the functionality of the findBy* / findAllBy* magic methods.

  • settings array

    Contains configuration settings for use with individual model objects. This is used because if multiple models use this Behavior, each will use the same object instance. Individual model settings should be stored as an associative array, keyed off of the model name.

_addToWhitelist

top

If $model's whitelist property is non-empty, $field will be added to it. Note: this method should only be used in beforeValidate or beforeSave to ensure that it only modifies the whitelist for the current save operation. Also make sure you explicitly set the value of the field which you are allowing.

Parameters:
  • object $model required

    Model using this behavior

  • string $field required

    Field to be added to $model's whitelist

Method defined in:
cake/libs/model/model_behavior.php on line 196
Access

protected

Return

void

afterDelete

top

After delete callback

Parameters:
  • object $model required

    Model using this behavior

Method defined in:
cake/libs/model/model_behavior.php on line 143
Access

public

afterFind

top

Resets original associations on models that may have receive multiple, subsequent unbindings.

Parameters:
  • object $Model required

    Model on which we are resetting

  • array $results required

    Results of the find operation

  • bool $primary required

    true if this is the primary model that issued the find operation, false otherwise

Method defined in:
cake/libs/model/behaviors/containable.php on line 231
Access

public

afterSave

top

After save callback

Parameters:
  • object $model required

    Model using this behavior

  • boolean $created required

    True if this save created a new record

Method defined in:
cake/libs/model/model_behavior.php on line 125
Access

public

beforeDelete

top

Before delete callback

Parameters:
  • object $model required

    Model using this behavior

  • boolean $cascade optional true

    If true records that depend on this record will also be deleted

Method defined in:
cake/libs/model/model_behavior.php on line 135
Return

boolean True if the operation should continue, false if it should abort

Access

public

beforeFind

top

Runs before a find() operation. Used to allow 'contain' setting as part of the find call, like this:

Model->find('all', array('contain' => array('Model1', 'Model2')));

Model->find('all', array('contain' => array(
    'Model1' => array('Model11', 'Model12'),
    'Model2',
    'Model3' => array(
        'Model31' => 'Model311',
        'Model32',
        'Model33' => array('Model331', 'Model332')
)));

Parameters:
  • object $Model required

    Model using the behavior

  • array $query required

    Query parameters as set by cake

Method defined in:
cake/libs/model/behaviors/containable.php on line 99
Return

array

Access

public

beforeSave

top

Before save callback

Parameters:
  • object $model required

    Model using this behavior

Method defined in:
cake/libs/model/model_behavior.php on line 116
Return

boolean True if the operation should continue, false if it should abort

Access

public

beforeValidate

top

Before validate callback

Parameters:
  • object $model required

    Model using this behavior

Method defined in:
cake/libs/model/model_behavior.php on line 107
Return

boolean True if validate operation should continue, false to abort

Access

public

cakeError

top

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 required

    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

Method defined in:
cake/libs/object.php on line 187
Return

error message

Access

public

cleanup

top

Clean up any initialization this behavior has done on a model. Called when a behavior is dynamically detached from a model using Model::detach().

Parameters:
  • object $model required

    Model using this behavior

Method defined in:
cake/libs/model/model_behavior.php on line 73
Access

public

See

BehaviorCollection::detach()

__construct

top

Class constructor, overridden in descendant classes.

Method defined in:
cake/libs/object.php on line 54

contain

top

Unbinds all relations from a model except the specified ones. Calling this function without parameters unbinds all related models.

Parameters:
  • object $Model required

    Model on which binding restriction is being applied

Method defined in:
cake/libs/model/behaviors/containable.php on line 249

containments

top

Process containments for model.

Parameters:
  • object $Model required

    Model on which binding restriction is being applied

  • array $contain required

    Parameters to use for restricting this model

  • array $containments optional array ( )

    Current set of containments

  • bool $throwErrors optional NULL

    Wether unexisting bindings show throw errors

Method defined in:
cake/libs/model/behaviors/containable.php on line 289
Return

array Containments

Access

public

containmentsMap

top

Build the map of containments

Parameters:
  • array $containments required

    Containments

Method defined in:
cake/libs/model/behaviors/containable.php on line 439
Return

array Built containments

Access

public

dispatchMethod

top

Overrides Object::dispatchMethod to account for PHP4's broken reference support

Parameters:
  • $model required

  • $method required

  • $params optional array ( )

Method defined in:
cake/libs/model/model_behavior.php on line 161
See

Object::dispatchMethod

Access

public

Return

mixed

fieldDependencies

top

Calculate needed fields to fetch the required bindings for the given model.

Parameters:
  • object $Model required

    Model

  • array $map required

    Map of relations for given model

  • mixed $fields optional array ( )

    If array, fields to initially load, if false use $Model as primary model

Method defined in:
cake/libs/model/behaviors/containable.php on line 393
Return

array Fields

Access

public

log

top

Convience 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/libs/object.php on line 148
Return

boolean Success of log write

Access

public

Object

top

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

Method defined in:
cake/libs/object.php on line 43
Return

Object

onError

top

DataSource error callback

Parameters:
  • object $model required

    Model using this behavior

  • string $error required

    Error generated in DataSource

Method defined in:
cake/libs/model/model_behavior.php on line 152
Access

public

_persist

top

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 required

    name of the class to persist

  • $return required

  • string $object required

    the object to persist

  • $type optional NULL

Method defined in:
cake/libs/object.php on line 218
Return

boolean Success

Access

protected

Todo

add examples to manual

requestAction

top

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 required

    String or array-based url.

  • array $extra optional array ( )

    if array includes the key "return" it sets the AutoRender to true.

Method defined in:
cake/libs/object.php on line 80
Return

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

Access

public

resetBindings

top

Permanently restore the original binding settings of given model, useful for restoring the bindings after using 'reset' => false as part of the contain call.

Parameters:
  • object $Model required

    Model on which to reset bindings

Method defined in:
cake/libs/model/behaviors/containable.php on line 264
Return

void

Access

public

_savePersistent

top

You should choose a unique name for the persistent file

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

Parameters:
  • string $name required

    name used for object to cache

  • object $object required

    the object to persist

Method defined in:
cake/libs/object.php on line 247
Return

boolean true on save, throws error if file can not be created

Access

protected

_set

top

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.

Method defined in:
cake/libs/object.php on line 166
Return

void

Access

protected

setup

top

Initiate behavior for the model using specified settings.

Available settings:

  • recursive: (boolean, optional) set to true to allow containable to automatically determine the recursiveness level needed to fetch specified models, and set the model recursiveness to this level. setting it to false disables this feature. DEFAULTS TO: true
  • notices: (boolean, optional) issues E_NOTICES for bindings referenced in a containable call that are not valid. DEFAULTS TO: true
  • autoFields: (boolean, optional) auto-add needed fields to fetch requested bindings. DEFAULTS TO: true

Parameters:
  • object $Model required

    Model using the behavior

  • array $settings optional array ( )

    Settings to override for model.

Method defined in:
cake/libs/model/behaviors/containable.php on line 67
Access

public

_stop

top

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

Parameters:
  • $status optional 0

Method defined in:
cake/libs/object.php on line 135
Return

void

Access

public

toString

top

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

Method defined in:
cake/libs/object.php on line 64
Return

string The name of this class

Access

public