codeigniter javascript phpquery |
[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?
[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.
[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
[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).
[eluser]InsiteFX[/eluser]
Simple fix for inline images. Code: <head>
[eluser]NeoArc[/eluser]
In PyroCMS they use BASE_URI, a 'bandwidth-friendly' constant. Code: //constants.php (old code??) |
Welcome Guest, Not a member yet? Register Sign In |