【发布时间】:2016-10-26 18:22:37
【问题描述】:
我已经阅读了很多关于此的主题(帖子末尾的列表),但我无法让我的代码正常工作。首先我使用的是旧的 Zend Framework 1.11。我有以下布局(只是一个例子):
<?php
$this->headScript('file','/js/jquery/jquery-1.12.4.min.js');
$this->headScript('file','/js/jquery/jquery-migrate-1.4.1.min.js');
// more CSS & JS files goes here
// some PHP code goes here
?>
<html>
<head>
<?php
echo $this->headLink();
echo $this->headStyle();
echo $this->headScript();
echo $this->headInline();
?>
</head>
...
</html>
这是我控制器的功能:
public function indexAction()
{
$this->view->headScript()->appendFile('/js/jsgrid.js', 'text/javascript');
$this->_helper->layout->setLayout('admin_console');
}
jsgrid.js 处的代码取决于要加载的 jQuery。我想从控制器加载文件作为最后一个,所以结果会是这样的:
<script type="text/javascript" src="/js/jquery/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="/js/jquery/jquery-migrate-1.4.1.min.js"></script>
<script type="text/javascript" src="/js/jsgrid.js"></script>
但是从上面的代码中我得到了这个:
<script type="text/javascript" src="/js/jsgrid.js"></script>
<script type="text/javascript" src="/js/jquery/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="/js/jquery/jquery-migrate-1.4.1.min.js"></script>
导致脚本失败的原因。我怎样才能做到这一点?有什么建议吗?
主题列表:
- ZendFramework - How to add ->HeadScript() from Controllers?
- Zend 1.12: Append javascript to bottom of view
- the best way to include js file in zend framework
- https://framework.zend.com/manual/2.4/en/modules/zend.view.helpers.head-script.html
- http://www.stoimen.com/blog/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/
- 还有 .... 更多
【问题讨论】:
标签: php zend-framework