^ to trigger the event like $this->getEventManager()->trigger('myEvent');

On Tue, Oct 1, 2013 at 9:34 AM, Richard Jennings
<richardjenni...@gmail.com> wrote:
> The Event Manager you are triggering the event on, say in a specific
> controller, has an array of Identifier properties.
>
> These Identifiers would ordinarily be set in
> Zend\Mvc\Controller\AbstractController::setEventManager for a
> controller.
> $events->setIdentifiers(array(
>             'Zend\Stdlib\DispatchableInterface',
>             __CLASS__,
>             get_class($this),
>             $this->eventIdentifier,
>             substr(get_class($this), 0, strpos(get_class($this), '\\'))
>         ));
>
> The class of the controller has been added as an Identifier to the
> Controllers Event Manager. (EventManagerAwareInterface on
> AbstractController causes Event Manager to be set by an initializer).
>
> The Shared Event Manager allows attaching an event that can only be
> triggered by Event Managers with a correct Identifier. From above,
> this can include inheritance ('Zend\Stdlib\DispatchableInterface') but
> we can use the controllers class to be more specific.
>
> Attach the event to a specific Identifier (the controller)
> $eventManager->attach('My\Controller\Class', 'myEvent', function($e) {
> die("it worked!");});
>
> so now with an event attached, in your controller you should be able
> to trigger the event like $this->eventManager->trigger('myEvent');
>
>
> On Tue, Oct 1, 2013 at 8:24 AM, Björn Rylander <hassl...@gmail.com> wrote:
>> I have no problem attaching an event to a wildcard context and triggering
>> it from a controller. But how do I set the correct context? If I want to be
>> able to trigger an event only from a specific controller, which is the
>> identifier I should pass as the context variable? I may be reading the docs
>> wrong, but they haven't been any help. If you have an example I would
>> appreciate it.
>>
>> With regards.
>>
>> Björn

--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com


Reply via email to