Join the Stack Overflow Community
Stack Overflow is a community of 6.3 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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.

share|improve this question

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

share|improve this answer

Heh. This is another "it depends" question. If you're writing JavaScript that will be used on every page, add it to the "master" page. If it's a one-off task, add it to the view that needs it.

share|improve this answer
    
Yeah, of course if it's used not once, I should add in one file. But I am asking how it should look like for, like you say, one-off task. – good_evening Aug 28 '11 at 8:38
    
So, are you asking for, say, sample code on how to do a partial-page refresh on a view or section of a view? – Tieson T. Aug 28 '11 at 8:41

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.