我是新来的编码器,我遇到这个问题,在config/config.php中的base_url为$config['base_url'] = 'localhost/codeigniter/index.php/stud/';
.
我在view/Stud_view.php中使用它
echo "<td><a href = '".base_url()."/edit/".$r->roll_no."'>Edit</a></td>";
但在地址栏显示为http://localhost/codeigniter/index.php/index.php/stud/edit/21
这里index.php出现了两次。如果我从地址栏中删除index.php,那么它工作得很好。这是怎么发生的?
您的base_url
应该是绝对的,包含协议,并且不包括index.php
:
$config['base_url'] = 'http://localhost/codeigniter/
你的URL可以构造为:
<?php
$url = site_url("stud/edit/" . $r->roll_no);
echo "<td><a href='" . $url . "'>Edit</a></td>";
?>
你的最终URL看起来像…
http://localhost/codeigniter/index.php/stud/edit/{roll_no}
site_url()
函数将包含由index_page
配置设置定义的"index.php"。(base_url()
函数将不包含"index.php").
看到:codeigniter.com/userguide3/helpers/url_helper.html # site_url
从base_url配置中删除url。变化:
$config['base_url'] = 'localhost/codeigniter/index.php/stud/';
:
$config['base_url'] = '';
并将url更改为:
echo "<td><a href = '".site_url()."/edit/".$r->roll_no."'>Edit</a></td>";