zend framework2 - Get controller name from Module.php -


i managed subscribe ondispatch() method in application\module.php more routing information should available onbootstrap().

public function onbootstrap(mvcevent $e) {     $em = $e->getapplication()->geteventmanager();      $em->attach(\zend\mvc\mvcevent::event_dispatch, array($this, 'ondispatch')); }  public function ondispatch(\zend\mvc\mvcevent $e) {     //$controllername = /* ... ? */;     $e->getviewmodel()->setvariables(         array('controllername'=> $controllername,         'actionname' => $actionname)     ); return parent::ondispatch($e); 

what need call the controller name? , mean not class, say, if controller class if application\controller\mycontroller, receive my-controller found in url. not string matching on url not want rely on due possible more complex routing.

also, if know, please tell me how can action name well.

you can information routematch available in mvcevent in dispatch listener.

public function ondispatch(\zend\mvc\mvcevent $e) {     $routematch = $e->getroutematch();     $controller = $routematch->getparam('controller');     $action = $routematch->getparam('action'); } 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -