Tamás Barta
Tamás Barta

Reputation: 1628

Is there a way to get the config for a dynamically loaded behavior in CakePHP 2.x?

Example:

$Model->Behaviors->load('Some.Behaviour', $options);

// Now how do I get $options back from the model?

Is there a way to get $options? $Model->actsAs remains empty.

Upvotes: 0

Views: 101

Answers (1)

Oldskool
Oldskool

Reputation: 34837

Those options are stored in the settings property of the Behavior itself. You can get to it by using:

$this->Behaviors->Behavior->settings[''];

For example:

$this->Behaviors->load('Containable', array('hello' => 'world'));
var_dump($this->Behaviors->Containable->settings);

Would return:

array (size=2)
  'priority' => int 10
  '' => 
    array (size=4)
      'recursive' => boolean true
      'notices' => boolean true
      'autoFields' => boolean true
      'hello' => string 'world' (length=5)

As you can see, the "hello world option" is right there at the bottom.

Upvotes: 1

Related Questions