Welcome Guest, Not a member yet? Register   Sign In
I'm tasked with using relative file referencing. Is that even possible w/ CI??

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:

<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:

<img src="/foo.gif" />

Can someone please help?

Thank you!

must be relative?

you can try base_url()

<img src="&lt;?=base_url();?&gt;foo.gif" />

if your base_url is www.site.com, so the img src will be
<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.


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

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

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

Theme © iAndrew 2016 - Forum software by © MyBB