Welcome Guest, Not a member yet? Register   Sign In
My links do not work at all
#1

[eluser]Coder Death[/eluser]
Hello to all,
I am having problem with links. When I am on the home page , all the links work fine but if I enter one link and try from that page to enter another link it gets error.
I explain
My home page
Code:
localhost/index.php

with the following two links
Code:
href="link1">Link1<
Code:
href="link2">Link2<

when i point to Link1 the address is showing
Code:
localhost/index/controller/link1
That is ok
But if I enter Link1 and point now on link2 the link displays is
Code:
localhost/index/controller/link1/index/controller/link1

So it CodeIgniter adds
Code:
/index/controller/link1
Why ?
What am I ignoring in the configuration file? Please.
My config file is set to
Code:
$config['index_page'] = 'index.php';


How can I remove it and make that it does not appear in my links anymore?
#2

[eluser]marcogmonteiro[/eluser]
you should use:

Code:
<a href="&lt;?= site_url('controller/method/param') ?&gt;">link1</a>

or

Code:
&lt;?= anchor('controller/method/param', 'link1') ?&gt;
#3

[eluser]Coder Death[/eluser]
and what about

Code:
<a href="&lt;?php echo base_url();?&gt;controller/function/param">Link1</a>

?
No need?
#4

[eluser]Coder Death[/eluser]
Anyway
Code:
&lt;?=site_url('controller/function/param');?&gt;
works for me
Thanks a lot
#5

[eluser]marcogmonteiro[/eluser]
base url would work too, but only if you have a re-write rule to remove your index.php. Site_url is safer because that will work either way, if you have re-write rules or not.
#6

[eluser]Coder Death[/eluser]
Ok @marcogmonteiro,
I get it. it works fine!
Thank a lot
#7

[eluser]CroNiX[/eluser]
It's actually not CI that is causing that issue. It was because you were using "relative paths", which is a common HTML issue. http://www.boogiejack.com/server_paths.html.

Remember, in CI, all paths are relative to the location of index.php, since that is what all CI urls get processed through. CI requests, not assets like images/js/css/etc. It's just best to use absolute paths for everything (which the CI url helpers generate)




Theme © iAndrew 2016 - Forum software by © MyBB