0

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.

mattalxndr
  • 9,143
  • 8
  • 56
  • 87

1 Answers1

1

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).

Steven Mercatante
  • 24,757
  • 9
  • 65
  • 109