![]() |
Weirdness when using URLs - 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: Weirdness when using URLs (/showthread.php?tid=11778) |
Weirdness when using URLs - El Forum - 09-23-2008 [eluser]Mr Lazy[/eluser] Hi, I am probably doing something stupid as this is my first try at sending a URL variable with CodeIgniter. I have a row of data, and the link that surrounds that row is this: Code: <a href="controllerName/functionName/id">Data Here</a> But when you hover the mouse over the link in the browser you see this: http://localhost/projects/controllerName/controllerName/functionName/id The controller name is doubled up, and of course this does not work. In the config.php file I have used this (as I read somewhere this was a good idea): Code: $config['base_url'] = "http://".$_SERVER['HTTP_HOST']; Strange thing is the source for the link is: Code: <a href="controllerName/functionName/id">Data Here</a> Which is correct. What's going on here? Many Thanks, L. Weirdness when using URLs - El Forum - 09-23-2008 [eluser]maesk[/eluser] Hi, the URL Code: <a href="controllerName/functionName/id">Data Here</a> is a relative link, that's why "http://localhost/projects/controllerName/" is already 'given' and you add to that again the controllerName/functionName/id. What you want is an absolute link. You could use base_url() or site_url() or anchor() from the URL helper. I usually do something like this: Code: href="<?php echo site_url('controller/function/params'); ?>" /> Read this section of the User Guide about the URL helper: http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html Weirdness when using URLs - El Forum - 09-23-2008 [eluser]Mr Lazy[/eluser] Thanks Grad Student, I had read that page but it did not sink in. Thanks for the pointer (it now works fine) and thanks for not saying RTFM! Lazy. Weirdness when using URLs - El Forum - 09-23-2008 [eluser]maesk[/eluser] You're welcome, "Summer Student" ;-) Please note, that my nick is maesk, "Grad Student" is my rank :-) Weirdness when using URLs - El Forum - 09-23-2008 [eluser]Mr Lazy[/eluser] Could I be any more of a newbie huh?? Thanks again maesk. |