My links do not work at all |
[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 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 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?
[eluser]marcogmonteiro[/eluser]
you should use: Code: <a href="<?= site_url('controller/method/param') ?>">link1</a> or Code: <?= anchor('controller/method/param', 'link1') ?>
[eluser]Coder Death[/eluser]
and what about Code: <a href="<?php echo base_url();?>controller/function/param">Link1</a> ? No need?
[eluser]Coder Death[/eluser]
Anyway Code: <?=site_url('controller/function/param');?> Thanks a lot
[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.
[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) |
Welcome Guest, Not a member yet? Register Sign In |