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 2.6 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.6
      • 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

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • AclNode
  • Aco
  • AcoAction
  • Aro
  • BehaviorCollection
  • CakeSchema
  • ConnectionManager
  • I18nModel
  • Model
  • ModelBehavior
  • ModelValidator
  • Permission

Class BehaviorCollection

Model behavior collection class.

Defines the Behavior interface, and contains common model interaction functionality.

ObjectCollection
Extended by BehaviorCollection implements CakeEventListener
Package: Cake\Model
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/Model/BehaviorCollection.php

Properties summary

  • $_mappedMethods protected
    array
    Keeps a list of all methods which have been mapped with regular expressions
  • $_methods protected
    array
    Keeps a list of all methods of attached behaviors
  • $modelName public
    string
    Stores a reference to the attached name

Inherited Properties

  • _enabled, _loaded, defaultPriority

Method Summary

  • attach() public deprecated
    Backwards compatible alias for load()
  • detach() public deprecated
    Backwards compatible alias for unload()
  • dispatchMethod() public
    Dispatches a behavior method. Will call either normal methods or mapped methods.
  • hasMethod() public

    Check to see if a behavior in this collection implements the provided method. Will also check mappedMethods.

  • implementedEvents() public

    Returns the implemented events that will get routed to the trigger function in order to dispatch them separately on each behavior

  • init() public
    Attaches a model object and loads a list of behaviors
  • load() public

    Loads a behavior into the collection. You can use use $config['enabled'] = false to load a behavior with callbacks disabled. By default callbacks are enabled. Disable behaviors can still be used as normal.

  • methods() public

    Gets the method list for attached behaviors, i.e. all public, non-callback methods. This does not include mappedMethods.

  • unload() public
    Detaches a behavior from a model

Method Detail

attach() public deprecated ¶

attach( string $behavior , array $config = array() )

Backwards compatible alias for load()

Deprecated
3.0.0 Will be removed in 3.0. Replaced with load().
Parameters
string $behavior
Behavior name.
array $config optional array()
Configuration options.

detach() public deprecated ¶

detach( string $name )

Backwards compatible alias for unload()

Deprecated
3.0.0 Will be removed in 3.0. Use unload instead.
Parameters
string $name
Name of behavior

dispatchMethod() public ¶

dispatchMethod( Model $model , string $method , array $params = array() , boolean $strict = false )

Dispatches a behavior method. Will call either normal methods or mapped methods.

If a method is not handled by the BehaviorCollection, and $strict is false, a special return of array('unhandled') will be returned to signal the method was not found.

Parameters
Model $model
The model the method was originally called on.
string $method
The method called.
array $params optional array()
Parameters for the called method.
boolean $strict optional false
If methods are not found, trigger an error.
Returns
array
All methods for all behaviors attached to this object

hasMethod() public ¶

hasMethod( string $method , boolean $callback = false )

Check to see if a behavior in this collection implements the provided method. Will also check mappedMethods.

Parameters
string $method
The method to find.
boolean $callback optional false
Return the callback for the method.
Returns
mixed

If $callback is false, a boolean will be returned, if its true, an array containing callback information will be returned. For mapped methods the array will have 3 elements.


implementedEvents() public ¶

implementedEvents( )

Returns the implemented events that will get routed to the trigger function in order to dispatch them separately on each behavior

Returns
array
Implementation of
CakeEventListener::implementedEvents()

init() public ¶

init( string $modelName , array $behaviors = array() )

Attaches a model object and loads a list of behaviors

Parameters
string $modelName
Model name.
array $behaviors optional array()
Behaviors list.

load() public ¶

load( string $behavior , array $config = array() )

Loads a behavior into the collection. You can use use $config['enabled'] = false to load a behavior with callbacks disabled. By default callbacks are enabled. Disable behaviors can still be used as normal.

You can alias your behavior as an existing behavior by setting the 'className' key, i.e.,

public $actsAs = array(
  'Tree' => array(
    'className' => 'AliasedTree'
  );
);

All calls to the Tree behavior would use AliasedTree instead.

Parameters
string $behavior
CamelCased name of the behavior to load
array $config optional array()
Behavior configuration parameters
Returns
boolean
True on success, false on failure
Throws
MissingBehaviorException
when a behavior could not be found.

methods() public ¶

methods( )

Gets the method list for attached behaviors, i.e. all public, non-callback methods. This does not include mappedMethods.

Returns
array
All public methods for all behaviors attached to this collection

unload() public ¶

unload( string $name )

Detaches a behavior from a model

Parameters
string $name
CamelCased name of the behavior to unload
Overrides
ObjectCollection::unload()

Methods inherited from ObjectCollection

__get() public ¶

__get( string $name )

Provide public read access to the loaded objects

Parameters
string $name
Name of property to read
Returns
mixed

__isset() public ¶

__isset( string $name )

Provide isset access to _loaded

Parameters
string $name
Name of object being checked.
Returns
boolean

attached() public deprecated ¶

attached( string $name = null )

Gets the list of attached objects, or, whether the given object is attached

Deprecated
3.0.0 Will be removed in 3.0. Use loaded instead.
Parameters
string $name optional null

Optional. The name of the object to check the status of. If omitted, returns an array of currently-attached objects

Returns
mixed

If $name is specified, returns the boolean status of the corresponding object. Otherwise, returns an array of all attached objects.


disable() public ¶

disable( string|array $name )

Disables callbacks on an object or array of objects. Public object methods are still callable as normal.

Parameters
string|array $name
CamelCased name of the objects(s) to disable (string or array)

enable() public ¶

enable( string|array $name , boolean $prioritize = true )

Enables callbacks on an object or array of objects

Parameters
string|array $name
CamelCased name of the object(s) to enable (string or array)
boolean $prioritize optional true
Prioritize enabled list after enabling object(s)

enabled() public ¶

enabled( string $name = null )

Gets the list of currently-enabled objects, or, the current status of a single objects

Parameters
string $name optional null

Optional. The name of the object to check the status of. If omitted, returns an array of currently-enabled object

Returns
mixed

If $name is specified, returns the boolean status of the corresponding object. Otherwise, returns an array of all enabled objects.


loaded() public ¶

loaded( string $name = null )

Gets the list of loaded objects, or, whether the given object is loaded

Parameters
string $name optional null

Optional. The name of the object to check the status of. If omitted, returns an array of currently-loaded objects

Returns
mixed

If $name is specified, returns the boolean status of the corresponding object. Otherwise, returns an array of all loaded objects.


normalizeObjectArray() public static ¶

normalizeObjectArray( array $objects )

Normalizes an object array, creates an array that makes lazy loading easier

Parameters
array $objects
Array of child objects to normalize.
Returns
array
Array of normalized objects.

prioritize() public ¶

prioritize( )

Prioritize list of enabled object

Returns
array
Prioritized list of object

set() public ¶

set( string $name = null , Object $object = null )

Adds or overwrites an instantiated object to the collection

Parameters
string $name optional null
Name of the object
Object $object optional null
The object to use
Returns
array
Loaded objects

setPriority() public ¶

setPriority( string|array $name , integer|null $priority = null )

Set priority for an object or array of objects

Parameters
string|array $name

CamelCased name of the object(s) to enable (string or array) If string the second param $priority is used else it should be an associative array with keys as object names and values as priorities to set.

integer|null $priority optional null
Integer priority to set or null for default

trigger() public ¶

trigger( string|CakeEvent $callback , array $params = array() , array $options = array() )

Trigger a callback method on every object in the collection. Used to trigger methods on objects in the collection. Will fire the methods in the order they were attached.

Options

  • breakOn Set to the value or values you want the callback propagation to stop on. Can either be a scalar value, or an array of values to break on. Defaults to false.

  • break Set to true to enabled breaking. When a trigger is broken, the last returned value will be returned. If used in combination with collectReturn the collected results will be returned. Defaults to false.

  • collectReturn Set to true to collect the return of each object into an array. This array of return values will be returned from the trigger() call. Defaults to false.

  • modParams Allows each object the callback gets called on to modify the parameters to the next object. Setting modParams to an integer value will allow you to modify the parameter with that index. Any non-null value will modify the parameter index indicated. Defaults to false.

Parameters
string|CakeEvent $callback

Method to fire on all the objects. Its assumed all the objects implement the method you are calling. If an instance of CakeEvent is provided, then then Event name will parsed to get the callback name. This is done by getting the last word after any dot in the event name (eg. Model.afterSave event will trigger the afterSave callback)

array $params optional array()
Array of parameters for the triggered callback.
array $options optional array()
Array of options.
Returns
mixed
Either the last result or all results if collectReturn is on.
Throws
CakeException
when modParams is used with an index that does not exist.

Properties detail

$_mappedMethods ¶

protected array

Keeps a list of all methods which have been mapped with regular expressions

array()

$_methods ¶

protected array

Keeps a list of all methods of attached behaviors

array()

$modelName ¶

public string

Stores a reference to the attached name

null
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