简体   繁体   中英

Zend Framework appendFile not working after jQuery include

I'm setting a local path for jQuery in my layout. Then adding another js file using appendFile, but it's not adding the file I'm appending.

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(); is being executed before any of your view code is, so it won't take your appendFile() statement into account. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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