Zend Framework 2 でルートの一致を公開するビュー プラグインをセットアップしようとしています。プラグインは次のようなものです。
class GetRouteMatch extends AbstractHelper
{
/**
* Route match returned by the router.
*
* @var RouteMatch.
*/
protected $routeMatch;
/**
* Set route match returned by the router.
*
* @param RouteMatch $routeMatch
* @return self
*/
public function setRouteMatch(RouteMatch $RouteMatch)
{
$this->routeMatch = $RouteMatch;
return $this;
}
public function __invoke($param)
{
return $this->routeMatch->getParam($param, false);
}
}
RouteMatch オブジェクトをセットアップする最良の方法は何ですか? モジュールのブートストラップまたはコントローラーでそれを行う必要がありますか?
今のところ、コントローラーアクション内でこの方法で解決しました
$renderer = $this->getLocator()->get('Zend\View\Renderer\PhpRenderer');
$routeMatch = $renderer->plugin('routeMatch');
$routeMatch->setRouteMatch($this->getEvent()->getRouteMatch());
RouteMatch オブジェクトは手動で注入されます..しかし、もっと良い方法があると確信しています