これは私がzf2beta5で作業するようになったソリューションになります
module / MyModule / Module.php
namespace MyModule;
use Zend\Mvc\ModuleRouteListener;
use MyModule\View\Helper as MyViewHelper;
class Module
{
public function onBootstrap($e)
{
$app = $e->getApplication();
$serviceManager = $app->getServiceManager();
$serviceManager->get('viewhelpermanager')->setFactory('myviewalias', function($sm) use ($e) {
return new MyViewHelper($e->getRouteMatch());
});
}
...
}
module / MyModule / src / MyModule / View / Helper.php
namespace MyModule\View;
use Zend\View\Helper\AbstractHelper;
class Helper extends AbstractHelper
{
protected $route;
public function __construct($route)
{
$this->route = $route;
}
public function echoController()
{
$controller = $this->route->getParam('controller', 'index');
echo $controller;
}
}
任意のビューファイル
$this->myviewalias()->echoController();