Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add script files using headScript with Zend Framework?

I am developing a new zend framework application, and when I just hard coded the headScript section for my layout.phtml file and Bootstrap _initScript method, when looking at the source-code after not having the script loaded... a got a really weird result.

I got this:

<script type="text/javascript">
    //<!--
    /js/jquery-1.8.1.min.js    //-->

Here is my layout.phtml code:

<?php echo $this->doctype(); ?> 
<html>
    <head>
        <?php echo $this->headTitle(); ?>
        <?php echo $this->headLink(); ?>
        <?php echo $this->headScript(); ?>
    </head>
    <body>
        <?php echo $this->layout()->content; ?>
    </body> 
</html>

Here is my Bootstrap.php code:

protected function _initScript()
{
    $this->view->headScript()
       ->prependScript( "/js/jquery-1.8.1.min.js" );
}

As you can see it is very ordinary code!

Anybody could help me find out what's going on here?

like image 596
Gilberto Albino Avatar asked Jul 30 '26 02:07

Gilberto Albino


1 Answers

You are trying to add "file" not "script".

Change Bootstrap.php to:

protected function _initScript()
{
    $this->view->headScript()
       ->prependFile( "/js/jquery-1.8.1.min.js", $type = 'text/javascript' );
}

Also check this for headScript reference.

Any questions? :)

like image 75
Karma Avatar answered Aug 02 '26 20:08

Karma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!