我正在使用zend框架来创建一个Web项目,我想知道是否有一种方法可以在模板中插入或查看javascript文件,具体取决于操作类型。例如,如果我有这个动作:
public function indexAction() {
$this->_helper->layout->setLayout("layout_ember");
//$this->headScript()->appendFile('/scripts/menu.js'); //no work
}
我想将文件menu.js添加到视图/模板中。
你能帮我解决这个问题吗?
我正在使用Zend Framework版本:1.12.0
答案 0 :(得分:2)
试试这个:
在你的行动中:
在视图底部添加js
$this->view->InlineScript()->appendFile($this->view->baseUrl() .'/scripts/menu.js');
在标题
中添加js$this->view->headScript()->appendFile($this->view->baseUrl() .'/scripts/menu.js'); //
在你的布局中 对于头部的js:
<head>
<?php
echo $this->headScript() ;
?>
</head>
对于底部的js:
<?php
echo $this->InlineScript();
?>
</body>
答案 1 :(得分:0)
这应该有效
$this->view->headScript()->appendFile('/path/to/file.js');