Welcome Guest, Not a member yet? Register   Sign In
can I call a javascript from within a controller ?
#3

[eluser]bretticus[/eluser]
To add to vitoco's sentiments. No, you cannot call javascript from PHP code. Get in the habit of putting javascript in the View part of MVC. Javascipt is only ran from the clients browser (thus client-side code) and PHP runs on your server to generate dynamic content for your browser (server-side code.)

Another suggestion: you can (and should) seperate your javascript from your view. IN other words, use something like jquery to "latch on" to your HTML DOM elements instead of having PHP render javascript calls inline. I did a project several years ago (and failed miserably because it was huge and I had all this javascipt mixed into my coding. What a kludge!) I learned the hard way that having your javascript as a separate container of your layout is crucial to keeping your code and functionality easy to debug and update. In fact, the principle of hijax is just so darned appealing that I'm providing link's:

the principle

A good video example. (He doesn't mention hijax but that is what he is doing when he turns javascript off.)

A short written example


Messages In This Thread
can I call a javascript from within a controller ? - by El Forum - 01-23-2010, 08:39 PM
can I call a javascript from within a controller ? - by El Forum - 01-24-2010, 12:25 AM
can I call a javascript from within a controller ? - by El Forum - 01-24-2010, 12:45 AM
can I call a javascript from within a controller ? - by El Forum - 01-25-2010, 05:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB