• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trailing slash and links

#1
Hi

if the url is 

Code:
localhost/controller/method/
<a href="some_link">link</a> -> it points to localhost/controller/method/some_link



But if there is no slash

Code:
localhost/controller/method
<a href="some_link">link</a> -> it points to localhost/controller/some_link (method is not included here)

How can i fix this. I want the link to include method name.
Thanks
Reply

#2
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');
Reply

#3
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...am1/param2
Then the anchor would link to:
http://yoursite.com/some_controller/some.../some_link
Reply

#4
Thank you friends!
I got it fixed!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.