Zend Framework: how to add a JavaScript element after running scripts?

I have a part that loads all the common links and styles in my head, and I use setScript on other pages for local scripts. I want to add the following script, which is in my view / scripts after other scripts, but zf adds it first:

<? $this->headScript()->setScript('$(document).ready(function() { $("#birthdate").datepicker(); });', $type = 'text/javascript') ?> 

which leads to the following code:

 <script type="text/javascript"> $(document).ready(function() { $("#birthdate").datepicker(); }); </script> <script type="text/javascript" src="/js/jquery-1.7.1.min.js"></script> <script type="text/javascript" src="/js/jquery.dcmegamenu.1.3.3.min.js"></script> <script type="text/javascript" src="/js/jquery.hoverIntent.minified.js"></script> <script type="text/javascript" src="/js/jquery-ui-1.8.16.custom.min.js"></script> 

but I want:

 <script type="text/javascript" src="/js/jquery-1.7.1.min.js"></script> <script type="text/javascript" src="/js/jquery.dcmegamenu.1.3.3.min.js"></script> <script type="text/javascript" src="/js/jquery.hoverIntent.minified.js"></script> <script type="text/javascript" src="/js/jquery-ui-1.8.16.custom.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#birthdate").datepicker(); }); </script> 
+4
source share
1 answer

Try calling:

 <? $this->headScript()->appendScript('$(document).ready(function() { $("#birthdate").datepicker(); });', $type = 'text/javascript') ?> 

Try adding other files using:

 <? $this->setScript() ->prependFile('/js/jquery-ui-1.8.16.custom.min.js') ->prependFile('/js/jquery.hoverIntent.minified.js') ->prependFile('/js/jquery.dcmegamenu.1.3.3.min.js') ->prependFile('/js/jquery-1.7.1.min.js') ; ?> 
+6
source

Source: https://habr.com/ru/post/1386768/


All Articles