Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend headScript() and appendFile not working as expected

I'm having an issue trying to append a javascript file using headScript()->appendFile('file name') with Zend. I have my layout setup like this:

    <?= $this->headScript()
    ->prependScript( 'BASE_URL = "' . $this->baseUrl() . '";' )
    ->appendFile( $this->baseUrl('js/lib/jquery/jquery-1.4.2.min.js') )
    ->appendFile( $this->baseUrl('js/admin.js') );

?>

Then, in my controller I am trying to append an additional js file only for this page, like:

    $this->view->headScript()->appendFile( 'another/js/file.js' );

This file needs to be appended to what is already setup in the layout. However, this file gets added before the other 'appendFile' files. I've also tried

$this->headScript()->offsetSetFile(999, '/js/myfuncs.js');

But this still adds the file before the other files. This is not how I would expect this to work, especially when using the offsetSetFile method. How can I add this file after the other files? Thanks.

like image 277
Ryan Avatar asked Mar 12 '10 17:03

Ryan


1 Answers

The answer is to use headScript()->prependFile in layout.phtml and headScript()->appendFile in a view.

like image 67
ejnadall Avatar answered Nov 07 '22 15:11

ejnadall