![]() |
codeigniter javascript phpquery - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: codeigniter javascript phpquery (/showthread.php?tid=53295) |
codeigniter javascript phpquery - El Forum - 07-18-2012 [eluser]joeizang[/eluser] hi y'all, I am building an application and I have need to use the base_url() function or site_url() in javasript with my codeigniter so I don't have to hardcode links in. I have come across a lot of solutions that seem to be messy. One of codeigniter's strong points that attracted me is the simplicity and cleanliness of code solutions. So I ran into a problem where I wanted to change a header image that I set with CSS but with javascript it gets hicky up and all that so I wanted to know if I can use phpquery to stuff like jquery? And if so how do we make it a library to use normally like native codeigniter libraries? codeigniter javascript phpquery - El Forum - 07-18-2012 [eluser]CroNiX[/eluser] In the head of your document, before you load any of your own js files: Code: <skript type="text/javascript"> Now, base_url and site_url are available to any javascript... For images in css, I just use: Code: background-image:url('/images/paper.gif'); http://yoursite.com/images/paper.gif Another advantage to that is it works on pages with or without ssl without having to adjust it. It will just assume the current protocol. codeigniter javascript phpquery - El Forum - 07-18-2012 [eluser]joeizang[/eluser] Thanks croNix, I will try this and let you know. codeigniter javascript phpquery - El Forum - 07-20-2012 [eluser]joeizang[/eluser] CroNix, Thanks for the tip cos it pointed me in the right direction. I am using the template library created by phil sturgeon so I had to do add this bit of code to make it work: Code: $this->template->append_metadata('[removed]var base_url = '.base_url().'[removed]'); This had the effect that you spoke of. Very well played sir. Thank you codeigniter javascript phpquery - El Forum - 07-22-2012 [eluser]NeoArc[/eluser] If you are testing stuff in shared servers, you may want to use relative paths in the css files: background-image: url("../img/demo.css"); http://css-tricks.com/quick-reminder-about-file-paths/ This is useful when the top directory is probably not the same as your domain root directory (development && testing environments). codeigniter javascript phpquery - El Forum - 07-22-2012 [eluser]InsiteFX[/eluser] Simple fix for inline images. Code: <head> codeigniter javascript phpquery - El Forum - 07-22-2012 [eluser]NeoArc[/eluser] In PyroCMS they use BASE_URI, a 'bandwidth-friendly' constant. Code: //constants.php (old code??) |