Trailing slash and links - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17) +--- Thread: Trailing slash and links (/showthread.php?tid=61315) |
Trailing slash and links - agriz - 04-08-2015 Hi if the url isĀ Code: localhost/controller/method/ But if there is no slash Code: localhost/controller/method How can i fix this. I want the link to include method name. Thanks RE: Trailing slash and links - davidgv88 - 04-08-2015 Hi agriz The best method is use site_url() function. For example: <a href="<?php echo site_url('controller/method') ?>">link</a> or <a href="<?php echo site_url('controller/method/some_link') ?>">link</a> or <a href="<?php echo site_url('controller/method/?foo=bar') ?>">link</a> In your controller add: $this->load->helper('url'); otherwise you can add in application/config/autoload.php $autoload['helper'] = array('url'); RE: Trailing slash and links - CroNiX - 04-08-2015 Or if you're just adding additional segments to the CURRENT url (using url helper): PHP Code: <a href="<?php echo current_url(); ?>/some_link">Link</a> If you were on: http://yoursite.com/some_controller Then the anchor would link to: http://yoursite.com/some_controller/some_link If you were on: http://yoursite.com/some_controller/some_method/param1/param2 Then the anchor would link to: http://yoursite.com/some_controller/some_method/param1/param2/some_link RE: Trailing slash and links - agriz - 04-08-2015 Thank you friends! I got it fixed! |