0
例如我有echo $this->escape($this->test);
in index.phtml和在控制器$this->view->test = 'test message';
,但我想從bootstrap這樣做,因爲我想在每個頁面(控制器)顯示窗體。Zend Framework:如何使從視圖bootstrap.php
例如我有echo $this->escape($this->test);
in index.phtml和在控制器$this->view->test = 'test message';
,但我想從bootstrap這樣做,因爲我想在每個頁面(控制器)顯示窗體。Zend Framework:如何使從視圖bootstrap.php
抱歉,我做到了
$view = new Zend_View;
$view->setBasePath(APPLICATION_PATH . "/views");
$view->arr = 'message';
echo $view->render('test.php');
protected function _initView()
{
$this->view = new Zend_View();
$this->view->test = 'test message';
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
$viewRenderer->setView($this->view);
}
但我會建議不引導期間在控制器插件這樣做,:
<?php
class My_Controller_Plugin_AddSomethingToViewInAllControllerActions extends Zend_Controller_Plugin_Abstract
{
public function preDispatch()
{
$viewRenderer = Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer');
$viewRenderer->initView();
$view = $viewRenderer->view;
$view->test = 'test message';
}
}