我正在使用Zend_view / Zend_Layout,但我希望能够根据控制器将脚本附加到整个模板,因此在控制器中我可以执行以下操作:
public function someAction()
{
$something->headScript()->appendFile('script.js','text/javascript');
// etc etc
}
我已经启用了Zend_view / Zend_Layout:
app.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;
}
答案 0 :(得分:3)
这有用吗?
public function someAction()
{
$this->view->headScript()->appendFile('script.js','text/javascript');
// etc etc
}
答案 1 :(得分:1)
放入布局模板
{headScript()}
在控制者的行动中:
$this->view->headScript()->appendFile('path/to/script.js');