0

这是我的代码:

class Module
{
    public function onBootstrap(MvcEvent $e)
    {

       $app = $e->getParam('application');
       $app->getEventManager()->attach('pre.loadevents',array($this,'preLoadEvents'));
       $app->getEventManager()->attach('loadevents',array($this,'loadEvents'));
       $app->getEventManager()->attach('post.loadevents',array($this,'postLoadEvents'));
       $app->getEventManager()->trigger('loadevents',null,[]);
    }       

    public function preLoadEvents(MvcEvent $e)
    {

    }

    public function postLoadEvents(MvcEvent $e)
    {

    }

    public function loadEvents(MvcEvent $e)
    {

        $app = $e->getParam('application');
        $eventsConfig = yoda::config('module/application/events/event');
        foreach($eventsConfig as $event){
            if((int)$event->active===0)continue;
            $app->getEventManager()->attach($event->name,array($this,$event->method));
        }

    }
}

使用它后,我得到Fatal error: Uncaught TypeError: Argument 1 passed to Application\Module::loadEvents() must be an instance of Zend\Mvc\MvcEvent, instance of Zend\EventManager\Event given. 我做错了什么

4

1 回答 1

0

你应该有

public function loadEvents(\Zend\EventManager\Event $e)
{
   ...
}

代替

public function loadEvents(MvcEvent $e)
{
   ...
}

因为这不是您来到这里的 MVC 事件。

于 2016-08-31T17:37:56.917 回答