Welcome Guest, Not a member yet? Register   Sign In
javascript in Codeigniter
#1

[eluser]mparas[/eluser]
Hello everyone!

I am new to codeigniter. I just wonder if javascript will work in Codeigniter with PHP?
#2

[eluser]stingray9[/eluser]
Sure, just link your .js file in your view like:

Code:
type="text/javascript" src="pathofyourfile.js">
#3

[eluser]planetCJD[/eluser]
I tend to just write my javascript in seperate view files and load them up into my final layout or you might want to look at this: http://ellislab.com/codeigniter/user-gui...cript.html
#4

[eluser]mparas[/eluser]
I haven’t tested yet but thank you so much for the reply. I’ll get back back to this thread if how was the result. grin
#5

[eluser]CroNiX[/eluser]
Look into asset managers so you can dynamically add css/js (links or raw code) to the head of your document via the controller or config file.

Here is one I use a lot: http://ellislab.com/forums/viewthread/101236/
Here is another, Carabiner, that is also popular but I havent used (because the first one already does everything I need): http://codeigniter.com/wiki/Carabiner/
#6

[eluser]mparas[/eluser]
:-) @CroNiX, thanks!
#7

[eluser]darkhouse[/eluser]
mparas: I just rewrote my External library to be much more flexible. You can check it out here http://ellislab.com/forums/viewthread/181405/

CroNiX: Thanks for the props, I hope you find the new library even more useful!
#8

[eluser]CroNiX[/eluser]
@darkhouse Cool, will check it out! Thanks!

One thing I did on your other one was add a boolean parameter to the run function. If it was true, it would output a timestamp of the modified file time for local assets on the server (css/js). This helped a lot with forcing the browser to reload/recache the file(s) if they had changed.

So it would output like <skript src="/js/jquery.tools.min.js?11072010" type="text/javascript" charset="utf-8"></skript>

If the jquery.tools.min.js file was ever changed, it would append the new modified date to the end to force the browser to recache the file.

Sorry for the hijack Smile
#9

[eluser]darkhouse[/eluser]
You know, that's a cool idea, I'll add that into the new version. Thanks!
#10

[eluser]darkhouse[/eluser]
Ok, I've added cache => false as an option for each asset, and also a default_cache setting in the config. So if you set the default to false, every file asset will have the timestamp appended unless cache is set to true in the individual asset options. And vice versa, if you set default_cache to true, no asset will have the timestamp appended unless you specify cache as false for the individual asset.




Theme © iAndrew 2016 - Forum software by © MyBB