Zend framework 2 preDispatch

Categories: zf2

Как сделать preDispatch и postDispatch actions в Zend Framework 2 ? код ниже

<?php
 
namespace Application\Controller;
 
use Zend\Mvc\Controller\ActionController
    Zend\Mvc\MvcEvent;
 
class IndexController extends ActionController
{
    public function indexAction()
    {
        return array();
    }
 
    protected function attachDefaultListeners()
    {
        parent::attachDefaultListeners();
 
        $events = $this->events();
        $events->attach('dispatch', array($this, 'preDispatch'), 100);
        $events->attach('dispatch', array($this, 'postDispatch'), -100);
    }
 
    public function preDispatch (MvcEvent $e)
    {
        // Called before self::indexAction()
    }
 
    public function postDispatch (MvcEvent $e)
    {
        // Called after self::indexAction()
    }
}

“100” и “-100” это порядок запуска действий.


No comments here yet Write here gently

No webmentions were found.

Comments powered by Talkyard.