我移植了一些编辑脚本,这些脚本重新调用了CI。它们第一次工作正常,但第二次不行。我看到是 URI 在不断增长。
在尝试在我的脚本中查找错误或将它们放在子文件夹中等事实后,我发现与此无关。
我设置了这个基本测试:控制器test_edit除了获取 url 字符串外什么都不做:
index()
{
$data['uri_string']=uri_string();
$this->load->view('test_edit',$data);
}
index2()
{
$data['uri_string']=uri_string();
$this->load->view('test_edit',$data);
}
VIEW test_edit只显示 url 字符串和指向控制器的链接:
<p>URI=<?=$uri_string ?></p>;
<p><a href="test_edit">test_edit</a></p>;
<p><a href="test_edit/index2">test_edit/index2</a></p>;
这导致
URI=
第一次点击第一个链接
后URI=test_edit/索引
第二次点击第一个链接
后URI=test_edit/test_edit/索引等
单击第二个链接将(显然)给出404错误。
我的问题:- WTF导致这种情况???为什么 URI 不刷新每个调用(缓存?),或者添加分段:浏览器、路由器类?
注意:不要告诉我使用base_url,URI翻译的全部意义在于不使用绝对标准URL或绝对路径。我知道如何解决这个问题,但我希望不必这样做。我想了解。
像这样声明<a> tags
:
<a href="<?=base_url('test_edit/index2')?>">test_edit/index2</a>
而不是:
<a href="test_edit/index2">test_edit/index2</a>
如果不使用base_url()
则使用CI
anchor()
:
anchor('string_path', 'title');