0

I have read a lot of topics about this (list at the end of the post) but I can't make my code to work. First I am using old Zend Framework 1.11. I have the following layout (just an example):

<?php
    $this->headScript('file','/js/jquery/jquery-1.12.4.min.js');
    $this->headScript('file','/js/jquery/jquery-migrate-1.4.1.min.js');
    // more CSS & JS files goes here
    // some PHP code  goes here
?>
<html>
    <head>
        <?php
           echo $this->headLink();
           echo $this->headStyle();
           echo $this->headScript();
           echo $this->headInline();
        ?> 
    </head>
    ...
</html> 

And this is the function at my controller:

public function indexAction()
{
    $this->view->headScript()->appendFile('/js/jsgrid.js', 'text/javascript');
    $this->_helper->layout->setLayout('admin_console');
}

The code at jsgrid.js depends on jQuery to be loaded. I want to load the file from the controller as the last one so the result would be something like:

<script type="text/javascript" src="/js/jquery/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="/js/jquery/jquery-migrate-1.4.1.min.js"></script>
<script type="text/javascript" src="/js/jsgrid.js"></script>

But from the code above I am getting this instead:

<script type="text/javascript" src="/js/jsgrid.js"></script>
<script type="text/javascript" src="/js/jquery/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="/js/jquery/jquery-migrate-1.4.1.min.js"></script>

Which is causing the script to fail. How I can achieve this? Any advice?

List of topics:

1 Answer 1

0

After several tries finally I have found the solution:

$this->view->inlineScript()->appendFile('/js/jsgrid.js', 'text/javascript');
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.