Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter JS
#1

[eluser]theprodigy[/eluser]
I have been using a javascript menu system for a little while and was curious if there was a way to have CI output the js via an MVC setup rather than always having to include the javascript files. Is it possible to have a script src point to a controller rather than an actual javascript file? I've tried to set it up, but it doesn't seem to work properly.

My end goal is to database the menu item list, and have a model that pulls the list from a db, then use a controller to organize it into the proper setup for the view to output the js needed. Is this possible, and if so, how would I go about doing this?

Thanks a bunch in advance for your help.
#2

[eluser]Nick Husher[/eluser]
You can point to CI controllers for javascript URIs on your page just as you would a 'flat' javascript file. The only thing that you might have to set is the content-type to "text/javascript", which can be done with the CI output class. My suggestion would be to create a webservice controller that allows you to request menu data in JSON format, then acquire that data via ajax from your frontend javascript (or embed the data in a hidden data island). This ensures loose coupling between the front and backend program structure.




Theme © iAndrew 2016 - Forum software by © MyBB