3

Well, I've read this tutorial if I could say: http://www.symfony-project.org/book/1_1/02-Exploring-Symfony-s-Code

And, actually, I write my code very similiary. But my question, where should I insert my jQuery code? I am sure it should be in the part of the View, but are there any good examples on how should I combine it to make "live" websites?

Edit: By saying live, I mean, for example, send POST request through Ajax and get information and similar. So, no refreshes for people.

Thank you.

2 Answers 2

0

jQuery as a part of javascript resources should be included in html.head or in-place, depending on what should jquery do and if the code is reusable for more views.

So it has to be part of View and you're choice is to set it up in layout or action view itself

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

Comments

0

If you need the javascript on every page then add it to your master view if not then just include it to the particular view files.

In context to codeigniter: I extend the controller with MY_Controller and initialize a property as array which would hold the scripts that are added dynamically to the view. eg.

var $templateData['scripts'] = array();

The controllers then pass $this->templateData to the views And the views load the extra scripts( available as $scripts) as directed by the controllers in the head tag

This way you can even avoid loading the main jquery file when not needed. Loading jquery.js only for the controller that need it.

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.