Behavior (class)

Class Behavior

Base class for behaviors.

Behaviors allow you to simulate mixins, and create reusable blocks of application logic, that can be reused across several models. Behaviors also provide a way to hook into model callbacks and augment their behavior.

Mixin methods

Behaviors can provide mixin like features by declaring public methods. These methods will be accessible on the tables the behavior has been added to.

function doSomething($arg1, $arg2) {
  // do something
}

Would be called like $table->doSomething($arg1, $arg2);.

Callback methods

Behaviors can listen to any events fired on a Table. By default CakePHP provides a number of lifecycle events your behaviors can listen to:

  • beforeFind(Event $event, Query $query, ArrayObject $options, boolean $primary) Fired before each find operation. By stopping the event and supplying a return