I'm creating a behavior (one template and one listener). In the template class, I'm using the addListener() method to attach the listener to the model.
// Inside the template's setTableDefinition() method
$this->addListener(new RemoraSaveListener);
Pretty standard stuff, it seems.
From within the listener, how to I access the template options that have been set using the model's actAs() method? You know, the ones that automatically occupy the _options property开发者_开发百科 of the template object.
Your template class should have a protected $_options = array()
property.
Pass this property to your listener, like so:
$this->addListener(new RemoraSaveListener($this->_options));
In your listener class you should also have a protected $_options
property.
Add this to your listener:
public function __construct($options) {
$this->_options = $options;
}
You should now be able to access the options from within your listener class (e.x from within a preSave
call).
精彩评论