我正在使用 zend 框架创建一个 web 项目,我想知道是否有一种方法可以根据操作类型插入模板或查看 javascript 文件。例如,如果我有这个 Action :
public function indexAction() {
$this->_helper->layout->setLayout("layout_ember");
//$this->headScript()->appendFile('/scripts/menu.js'); //no work
}
我想将文件 menu.js 添加到 View /模板。
你能帮我解决这个问题吗?
我正在使用 Zend Framework 版本:1.12.0
最佳答案
试试这个:
在你的行动中:
在 View 底部添加js
$this->view->InlineScript()->appendFile($this->view->baseUrl() .'/scripts/menu.js');
在header中添加js
$this->view->headScript()->appendFile($this->view->baseUrl() .'/scripts/menu.js'); //
在你的布局中 对于 head 中的 js:
<head>
<?php
echo $this->headScript() ;
?>
</head>
对于底部的js:
<?php
echo $this->InlineScript();
?>
</body>
关于javascript - 根据 Action 添加一个js文件。曾德,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22863445/