CodeIgniter Forums
Weird behavior with segments - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Weird behavior with segments (/thread-15693.html)



Weird behavior with segments - El Forum - 02-11-2009

[eluser]spyro[/eluser]
I am working on a controller that is used in an email confirmation. The email is a link that contains the id of the confirmation record. What happens is that I take the segments and parse them to execute the email confirmation. When the link is first called and processed by the controller the email is confirmed. The weird behavior is that after the first round the page tries to load a few images in the view. Each of those image loads also somehow get routed through the same controller. In firebug I can see that images are trying to load from a new_images folder. This folder doesn't exist and I also searched the code for new_images and it came up empty. Any ideas on what could be happening?


Weird behavior with segments - El Forum - 02-12-2009

[eluser]TheFuzzy0ne[/eluser]
Sounds like you are calling your images with a relative path, and not an absolute path.

If you prefix your image src attribute with a forward slash, it should start working.

Code:
<img src="/images/some_image.gif" alt="Some image" />

Alternatively, you can use base_url() to generate an absolute URL for your images.

Code:
&lt;img src="&lt;?php echo base_url() . 'images/some_image.gif'); ?&gt;" alt="Some image" />

But you will need to have loaded the URL helper:
Code:
$this->load->helper('url');

The second method is probably the best route to take.


Weird behavior with segments - El Forum - 02-12-2009

[eluser]xwero[/eluser]
TheFuzzy0ne it's best to use base_url because site_url can generate full urls like this : http://site.com/index.php/images/some_image.gif. This depends on whether the index_page setting has an empty string or not.


Weird behavior with segments - El Forum - 02-12-2009

[eluser]TheFuzzy0ne[/eluser]
My bad. I've changed the information. to reflect that. Thanks for pointing it out.