Answer the question
In order to leave comments, you need to log in
How to properly separate JS code for different views in Zend?
I am writing a Zend project for myself.
Bootstrap.php includes all my js and css files with:
$view->headScript()->appendFile('');
$view->headLink()->appendStylesheet('');
I have a main.js file that stores all the functionality.
As the functionality grew, a bunch of jQuery appeared inside the file:
$('#id').live('click', function() { ...
The
functionality will increase, and in the future, I will start to have problems associated with duplicates.
will make identifiers not #send, but #send_mail, #send_message, etc.
Although, in fact, I use send_mail in MailController, and send_message in MessageController
.
Please tell me in which direction I should look, or where to read about it. Or tell me what can be done with one large JS file, which includes JS logic from many different views.
Answer the question
In order to leave comments, you need to log in
Break JS into appropriate modules, use RequireJS to include the necessary modules.
I have described the general approach.
Have a look at the ZendX_JQuery native library framework.zend.com/manual/1.12/en/zendx.jquery.vie... there is a great $view->jQuery()-addOnload() method, through it and throw the necessary JS on your view helper or directly in the controller. In order not to write JS inside the PHP code, you can come up with some js templates. The bottom line is that for each view, controller or helper there will be only the js code that is needed at the moment.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question