0

I'm new in Zend Framework and I try to deal with some JS in my project. I have the following code in my layout.phtml:

<head>
    <!-- Scripts -->
    <?php echo $this->headScript()->prependFile($this->basePath() . '/js/html5.js', 'text/javascript', array('conditional' => 'lt IE 9',))
                                  ->prependFile($this->basePath() . '/js/jquery.min.js')
                                  ->prependFile($this->basePath() . '/js/bonsai.min.js')
                                  ->prependFile($this->basePath() . '/js/ui-controller.js'); ?>

</head>

My ui-controller.js contains simple JQuery script:

$(document).ready(function() {
    alert('test);
});

The problem is it isn't executed at all... I checked in Firebug in Chrome and my file is linked correctly. HTML code seems to be okay aswell... Can anyone help me?

[edit]
I wanted to say that I know I can use ZendX_JQuery plugin but I wonder how to use other JavaScript libraries when this one doesn't work...

[edit 2]

I get this error in the console:

Uncaught ReferenceError: $ is not defined ui-controller.js:1 GET
http://myproject.localhost/js/jquery-1.10.2.min.map 404 (Not Found)

4
  • Any javascript errors on the console? Commented Sep 12, 2013 at 21:49
  • Please, check my edit. I don't know why $ isn't defined. I have 1.10.2 JQuery plugin already included and a link in Firebug seems to be okay... Commented Sep 12, 2013 at 22:11
  • I replaced my minimized JQuery with dev version and I still get Uncaught ReferenceError: $ is not defined ui-controller.js:1 GET. Btw. Where to get .min.map file? Commented Sep 12, 2013 at 22:14
  • Could you check the order in which js files are loaded? Commented Sep 12, 2013 at 22:17

1 Answer 1

1

I'm guessing the order of your JS files is the issue. Because you are successively calling prependFile(), the ui-controller.js file will end up first in the HTML source, so it's loading before jQuery. Switch these calls to appendFile() instead (or reverse their order) and it should work fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.