例如我在index.phtml和控制器echo $this->escape($this->test);
中有$this->view->test = 'test message';
,但我想从bootstrap执行此操作,因为我想在每个页面(控制器)中显示Form。
答案 0 :(得分:1)
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';
}
}
答案 1 :(得分:0)
抱歉,我做到了
$view = new Zend_View;
$view->setBasePath(APPLICATION_PATH . "/views");
$view->arr = 'message';
echo $view->render('test.php');