CodeIgniter Forums
I'm tasked with using relative file referencing. Is that even possible w/ CI?? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: I'm tasked with using relative file referencing. Is that even possible w/ CI?? (/showthread.php?tid=3723)



I'm tasked with using relative file referencing. Is that even possible w/ CI?? - El Forum - 10-18-2007

[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


I'm tasked with using relative file referencing. Is that even possible w/ CI?? - El Forum - 10-18-2007

[eluser]ELRafael[/eluser]
must be relative?

you can try base_url()

Code:
<img src="&lt;?=base_url();?&gt;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!


I'm tasked with using relative file referencing. Is that even possible w/ CI?? - El Forum - 10-19-2007

[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 /.


I'm tasked with using relative file referencing. Is that even possible w/ CI?? - El Forum - 10-19-2007

[eluser]Michael Wales[/eluser]
I was about to say, referencing from root, ie:
Code:
<img src="/foo.gif" />
is relative.

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="&lt;?= retarded_helper($this->uri->total_segments()); ?&gt;/foo.gif" />



I'm tasked with using relative file referencing. Is that even possible w/ CI?? - El Forum - 10-19-2007

[eluser]Phil Sturgeon[/eluser]
Good point walesmd, you dont need to write a helper for that though.

Code:
<img src="&lt;?= repeater('../', $this->uri->total_segments()); ?&gt;foo.gif" />