2010-09-11 71 views

回答

0

抱歉,我做到了

$view = new Zend_View; 
    $view->setBasePath(APPLICATION_PATH . "/views"); 
    $view->arr = 'message'; 
    echo $view->render('test.php'); 
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'; 
    } 
} 
相關問題