Welcome Guest, Not a member yet? Register   Sign In
Relative Path
#1

[eluser]Costa Rica SEO[/eluser]
Greetings all,

I've been using CI for a week or so now and I decided to use one of my personal project sites as the testbed (3D-RPG System).

I have a little flash slideshow at the top of the page that loads info from an XML file. The problem is that the XML file has to use a relative path. I looked in the path helper, but that didn't seem to do what I wanted. I wrote the code below to count the number of segments in the URL, and add the appropriate number of "../" to access the root folder. It worked like a charm.

Code:
$x = $this->uri->total_segments();
$data['my_root'] = '';
  while ($x > 0) {
    $data['my_root'] .= '../';
    $x--;
  }

Does CI already have a function like this, or if not does anyone else think that this would be useful enough to include for the future? It's not like it's a lot of code, but it seems like something others would use. Thanks!
#2

[eluser]ecsyle31[/eluser]
I am not sure if there is a native codeigniter function to do what you want.

Could you supply the full url to the xml file?

Code:
so.addVariable("file", "<?php print base_url(); ?>slideshow/slideshow.xml")

Have you looked at str_repeat? You could use this instead of a loop to build your path.

Code:
$x = $this->uri->total_segments();
$data['my_root'] = str_repeat('../',$x);
#3

[eluser]Costa Rica SEO[/eluser]
Thanks for the fast reply. I can't do base_url because the flash file is hard coded to use a path relative from the current directory. So for each segment deep I need to back track to have the proper relative path.

Code:
so.addVariable("file", "<?php echo $my_root; ?>slideshow/slideshow.xml")

I was trying to figure out why it wasn't loading the flash file on different segments, and that's when I figured out it needed a relative path (not the absolute one that I was using). Anyway, I just thought something that gave a relative path to the root might be useful. It's not that hard to code, but it's the type of thing I expected in the path helper.

Thanks by the way for str_repeat, very useful.




Theme © iAndrew 2016 - Forum software by © MyBB