Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CodeIgniter-当我点击链接时,在我的URL中添加一个额外的类_Codeigniter - Fatal编程技术网

CodeIgniter-当我点击链接时,在我的URL中添加一个额外的类

CodeIgniter-当我点击链接时,在我的URL中添加一个额外的类,codeigniter,Codeigniter,我对CI和php都是新手。我有一个困扰我两天的问题: 当我点击我的管理员标题(比如:文章)中的链接时,它会把我带到:www.example.com/admin/Articles,这是可以的。如果现在我尝试单击标题中的另一个链接(比如:添加文章),url将变为:www.example.com/admin/admin/Add_articles-它会在我的url中添加一个额外的管理员。如果我再次单击文章,url将是:www.example.com/admin/admin/Articles,依此类推 你

我对CI和php都是新手。我有一个困扰我两天的问题:

当我点击我的管理员标题(比如:文章)中的链接时,它会把我带到:www.example.com/admin/Articles,这是可以的。如果现在我尝试单击标题中的另一个链接(比如:添加文章),url将变为:www.example.com/admin/admin/Add_articles-它会在我的url中添加一个额外的管理员。如果我再次单击文章,url将是:www.example.com/admin/admin/Articles,依此类推

你知道为什么会这样吗?
感谢使用绝对url而不是相对url,在每个链接之前使用$config['base\u url'.

您有两个选择,第一个是您在每个链接中写入base\u url() 或 您可以使用内置帮助器:

anchor('route','label','attributes')
在您的示例中:

anchor('admin/add_article','Add an article',array('class' => 'link'))
然后将创建以下HTML代码:

<a href="what is your base_url value/admin/add_article" class="link">Add an article</a>

不要使用

$config['base_url] . 'controller/action',
使用以下功能:

site_url('controller/action');

或者使用anchorás Rátz建议的锚函数。

用户绝对url不是相对的,在每个链接之前使用$config['base_url'],我总是使用anchor(),因为这样,如果我将代码上传到其他位置,我只需更改新url的配置文件。请接受我的回答:)谢谢