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 ViewHelperControllerName($e->getRouteMatch());
return $viewHelper;
});
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}
The actual ViewHelper:
// Application/View/Helper/ControllerName.php
namespace ApplicationViewHelper;
use ZendViewHelperAbstractHelper;
class ControllerName extends AbstractHelper
{
protected $routeMatch;
public function __construct($routeMatch)
{
$this->routeMatch = $routeMatch;
}
public function __invoke()
{
if ($this->routeMatch) {
$controller = $this->routeMatch->getParam('controller', 'index');
return $controller;
}
}
}
Inside any of your views/layouts
echo $this->controllerName()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…