コントローラーアクション外のview renderer
に汎用変数を割り当てたいとします。Zend Framework 2プロジェクトで共有ビューモデルを作成
私はこれをmodule class bootstrap
で処理したいと考えています。
私の質問は、コントローラと共有できるmodule class bootstrap
にview model
を作成するにはどうすればよいですか。
私の最終結果は、コントローラアクション内に新しいインスタンスを作成する前に、ビューモデルに変数を追加することができます。
ここで私が始めたのは、i cannot add variables to the declared viewmodel and have it persist to the controller's new instance of a view model
です。
ディスパッチ前にビューモデルを作成してレンダラーとして設定する方法はありますか?
ここに私が始めたことがありますが、私がモジュールクラスのブートストラップでそれを得ることができれば、idがそれを好む。
私はこれがうまくいくと思います。あなたはevent
オブジェクトへのアクセス権を持っているModule.php
で
class BaseController extends AbstractActionController
{
protected $viewModel;
public function onDispatch(MvcEvent $e)
{
$this->viewModel = new ViewModel([
'module' => 'modulename',
'controller' => 'controllername',
'action' => 'actionname'
]);
parent::onDispatch($e);
}
}