Welcome Guest, Not a member yet? Register   Sign In
Weirdness when using URLs
#1

[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.
#2

[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="&lt;?php echo site_url('controller/function/params'); ?&gt;" />


Read this section of the User Guide about the URL helper:
http://ellislab.com/codeigniter/user-gui...elper.html
#3

[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.
#4

[eluser]maesk[/eluser]
You're welcome, "Summer Student" ;-)
Please note, that my nick is maesk, "Grad Student" is my rank :-)
#5

[eluser]Mr Lazy[/eluser]
Could I be any more of a newbie huh?? Thanks again maesk.




Theme © iAndrew 2016 - Forum software by © MyBB