• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
odd relative path behaviour

#1
[eluser]neomech[/eluser]
Hi,

I'm fairly new to CI but I'm loving it and have built most of my app without too much trouble. I've run across something odd, and I'm not sure if it's a bug or if I'm just missing something obvious, so I thought I'd post here for help (let me know if there's somewhere better to post!)

I have the following bit of code in my routes.php file:

Code:
$route['(:any)-reviews'] = "category/parent/$1-reviews";
It works great. If someone goes to www.mysite.com/movie-reviews, it calls my "category" controller, the "parent" function, and passes "movie-reviews" to the function as a variable. I call a view from that controller that displays great, and of particular note (you'll see below why), all of my relative urls for my images work just fine. An image like public_html/images/image1.jpg can be called in the view using src="image/image1.jpg". If I inspect an image it returns the proper url of "http://www.mysite.com/images/image1.gif"

Now, I was messing with adding some additional information to my url (say, the number of movie reviews to return), and it works, but all of my image paths in my view go wonky.

So if I do something really basic like add this route (I'd normally use variables, but I'll just hardcode "shortlist" and "25" to show what I mean):

Code:
$route['(:any)-reviews/short_list'] = "category/parent/$1-reviews/25";

...everything works, I can add a second input to my controller that properly takes the "25", but all of my images fail, because now they all point to "http://www.mysite.com/movie-reviews/images/image1.gif".

Any idea what's happening here? I'd expect this behaviour maybe if I was using ../image/image1.gif, but if I'm using image/image1.gif, I expect it to be relative to the website's base url (if that makes sense).

I like relative paths and know I could make use of base_url() variables and such, but was just wondering why this was happening instead of just throwing my hands up in the air and doing it differently.

#2
[eluser]jedd[/eluser]
Hi neomech and welcome to the CI forums.

What mechanism are you using, in your view, to load your images?

It sounds like you're using embedded img src calls - but you know CI provides img() in the HTML helper?

#3
[eluser]BrianDHall[/eluser]
CodeIgniter HTML Helper Manual

Wow, I didn't know about the HTML help in CI actually - I just fell in love with CI all over again Big Grin

Aside from that, as to the thread topic...I'm actually surprised by that behavior too. In the view are you just doing regular HTML markup like "img src="? That definately would not be the behavior I'd expect either...

#4
[eluser]neomech[/eluser]
Hi guys, thanks for the feedback.

My images are currently just being called with regular old html in my view like so:
Code:
<img src="image/image1.gif">
I could try the html helper class, although I'd still like to know what's causing this odd behaviour.

#5
[eluser]jedd[/eluser]
[quote author="neomech" date="1252136926"]
I could try the html helper class, although I'd still like to know what's causing this odd behaviour.
[/quote]

If you do the first part of that sentence, and the problem goes away, you'll have answered the second part.

IOW you're experiencing the joy of routes and the way CI pipes everything through index.php (no matter what the URL suggests) and consequently life just becomes much simpler once you let CI handle pathing. Eg. by using img().


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.