1

我正在使用 Zend_view/Zend_Layout 但我希望能够根据控制器将脚本附加到整个模板,因此在控制器中我可以执行以下操作:

public function someAction()
{
    $something->headScript()->appendFile('script.js','text/javascript');
    // etc etc
}

我已经像这样启用 Zend_view/Zend_Layout:

在 application.ini 中:

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"

在 Bootstrap.php 中:

protected function _initView()
{
    $view = new Zend_View();
    $view->doctype('XHTML1_STRICT');
    $view->headTitle('zend layout tester');
    // Add it to the ViewRenderer
    $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
        'ViewRenderer'
    );
    $viewRenderer->setView($view); 
    // Return it, so that it can be stored by the bootstrap
    return $view;
}
4

2 回答 2

3

这行得通吗?

public function someAction()
{
    $this->view->headScript()->appendFile('script.js','text/javascript');
    // etc etc
}
于 2010-01-13T11:24:59.840 回答
1

放入布局模板

{headScript()}

在控制器的动作中:

$this->view->headScript()->appendFile('path/to/script.js');
于 2010-01-13T11:27:54.547 回答