I'm tasked with using relative file referencing. Is that even possible w/ CI?? |
[eluser]Unknown[/eluser]
Since CI requires slash notation (www.x.com/index.php/a/b/) and URL params also use slash notation (www.x.com/index.php/a/b/c/d/, where c and d are url input parameters) it's totally killing my web page's ability to properly resolve to images. In other words, my web pages refer to images like this: Code: <img src="foo.gif" /> Lets imagine that my image appears properly on this page: "www.x.com/index.php/a/b/" that's great. Now, if I pass a URL parameter (www.x.com/index.php/a/b/c/) my images won't load. Please note that I must use *relative* file referencing, not absolute. In other words, I am not able to use the following construct: Code: <img src="/foo.gif" /> Can someone please help? Thank you! Jon
[eluser]ELRafael[/eluser]
must be relative? you can try base_url() Code: <img src="<?=base_url();?>foo.gif" /> if your base_url is www.site.com, so the img src will be Code: <img src="www.site.com/foo.gif" /> well, this is not relative, hum? or, you can try htaccess (mod_rewrite) to redir dir! i didn't figure out why you can't use /foo.gif!
[eluser]Phil Sturgeon[/eluser]
Why can you not pass it absolute uri's? If it is submject to change, then you could use this helper I made to keep file locations dynamic and organised. http://styledna.pastebin.com/m66705718 You could make a slight modification to the line that creates the code, and replace base_url() with /.
[eluser]Michael Wales[/eluser]
I was about to say, referencing from root, ie: Code: <img src="/foo.gif" /> You could always count the number of uri->segments() there are, and append that number of ../ to the beginning of the filename. Why is a client forcing you to do this? Easily the most retarded thing I've ever heard, I'd drop the job right there if someone told me to do this - no benefit, more work for you, and the potential for major issues in the future. Regardless, make a helper to do the count and replace as I said earlier, and append that to the beginning of all URLs you want relative Code: <img src="<?= retarded_helper($this->uri->total_segments()); ?>/foo.gif" />
[eluser]Phil Sturgeon[/eluser]
Good point walesmd, you dont need to write a helper for that though. Code: <img src="<?= repeater('../', $this->uri->total_segments()); ?>foo.gif" /> |
Welcome Guest, Not a member yet? Register Sign In |