ZF2 – Get controller name into layout/views

ZF2 is out and so is the skeleton. This is adding on top of the skeleton so it should be your best example: Inside Module.php public function onBootstrap($e) { $e->getApplication()->getServiceManager()->get(‘translator’); $e->getApplication()->getServiceManager()->get(‘viewhelpermanager’)->setFactory(‘controllerName’, function($sm) use ($e) { $viewHelper = new View\Helper\ControllerName($e->getRouteMatch()); return $viewHelper; }); $eventManager = $e->getApplication()->getEventManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); } The actual ViewHelper: // … Read more

How to render ZF2 view within JSON response?

OK, i think i finally understood what you’re doing. I’ve found a solution that i think matches your criteria. Though i am sure that there is room for improvement, as there’s some nasty handwork to be done… public function indexAction() { if (!$this->getRequest()->isXmlHttpRequest()) { return array(); } $htmlViewPart = new ViewModel(); $htmlViewPart->setTerminal(true) ->setTemplate(‘module/controller/action’) ->setVariables(array( ‘key’ … Read more