Cake\ORM\Table::addBehavior PHP Method

addBehavior() public method

Adds a behavior to this table's behavior collection. Behaviors provide an easy way to create horizontally re-usable features that can provide trait like functionality, and allow for events to be listened to. Example: Load a behavior, with some settings. $this->addBehavior('Tree', ['parent' => 'parentId']); Behaviors are generally loaded during Table::initialize().
See also: Cake\ORM\Behavior
public addBehavior ( string $name, array $options = [] ) : void
$name string The name of the behavior. Can be a short class reference.
$options array The options for the behavior to use.
return void
    public function addBehavior($name, array $options = [])
    {
        $this->_behaviors->load($name, $options);
    }

Usage Example

 /**
  * testCamposEmArray
  *
  * @retun  void
  * @access public
  */
 public function testCamposEmArray()
 {
     $this->Noticias->addBehavior("CakePtbr.AjusteData", ["autorizado_em", "publicado_em"]);
     $noticia = $this->__preparaNoticia("25/03/15 16:42:05");
     $this->assertEquals("2015-03-22", $noticia->get("autorizado_em"));
     $this->assertEquals("2015-03-25 16:42:05", $noticia->get("publicado_em"));
 }
All Usage Examples Of Cake\ORM\Table::addBehavior