简体   繁体   中英

codeIgniter base url issue

Hi i am new in codeigniter, having trouble with link formation. In my page i have link to another page same to <a href = "<?php base_url('feed');?>"><li>Feed Page</li></a> here feed is one of my controller . But the link is showing to me as http://localhost/BusinessPad/localhost/BusinessPad/feed ---that actually doesn't exists. Can't understand how this happen. I have make $config['index_page'] = ''; and add a .htaccess file.

check for value you have assigned to base_url in you config.php file ,try site_url() , change:

<?php base_url('feed');?>

to

<?php echo site_url('feed'); ?>

you can create your own tag and insert a url in the href like this

<a href="<?php echo site_url('controller/function/uri') ?>">Link</a>

Or if you want to helper

you can use the URL helper this way to generate an tag

anchor(uri segments, text, attributes)

So... to use it...

<?php echo anchor('controller/function/uri', 'Link', 'class="link-class"') ?>

use this:-

<a href="<?php echo base_url('feed');?>">Link</a>

or

<a href="<?php echo base_url().'feed';?>">Link</a>

or

<a href="<?php echo base_url().'index.php/feed';?>">Link</a>
use this way
<a href = "<?php echo base_url();?>/index.php/feed">Feed Page</a>
or 
<a href = "<?= base_url() ;?>/index.php/feed">Feed Page</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM