简体   繁体   English

Zend Framework appendFile在jQuery包含后无法正常工作

[英]Zend Framework appendFile not working after jQuery include

I'm setting a local path for jQuery in my layout. 我在布局中为jQuery设置了本地路径。 Then adding another js file using appendFile, but it's not adding the file I'm appending. 然后使用appendFile添加另一个js文件,但未添加我要附加的文件。

in layout: 在布局中:

$jquery=$this->jQuery();
$jquery->enable(); // enable jQuery Core Library
$jquery->setLocalPath($this->baseUrl().'/js/jquery-1.3.2.min.js');
echo $jquery;
echo $this->headScript();

In my view: 在我看来:

$this->headScript()->appendFile($this->baseUrl().'/js/jquery.corner.js');

thanks for any help 谢谢你的帮助

You need to put the following line in your action, instead of your view: 您需要在操作中添加以下行,而不是视图:

$this->view->headScript()->appendFile($this->view->baseUrl().'/js/jquery.corner.js');

The line echo $this->headScript(); echo $this->headScript(); is being executed before any of your view code is, so it won't take your appendFile() statement into account. 是在您的任何视图代码之前执行的,因此不会考虑您的appendFile()语句。 If you put it in your action, the action code is called before the layout and view are rendered, so it will take it into account. 如果将其放入动作中,则在呈现布局和视图之前会调用动作代码,因此将其考虑在内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM