简体   繁体   English

codeigniter:为什么当我在锚标记的href属性中回显base_url()时,它回响两次

[英]codeigniter: why is that when i echo base_url() in an href attribute of an anchor tag, it echoes twice

so basically when i echo the codeigniter function base_url() in the href attribute of an anchor tag, it appears to echo it out twice. 因此,基本上,当我在锚标记的href属性中回显codeigniter函数base_url()时,它似乎回声了两次。 Example: 例:

<a href="<?php echo base_url(); ?>">somelink</a>

and the above, if you inspect it your chrome browser shows this: 以上,如果您对其进行检查,则chrome浏览器将显示以下内容:

<a href="www.mysitedomainname.com/www.mysitedomainname.com/">somelink</a>

"mysitedomainname.com" is just a name i made up for this example. “ mysitedomainname.com”只是我为此示例组成的名称。 Any reason why this is happening? 为什么会这样呢?

There are three reasons I'm aware about that can cause this. 我知道有三个原因可以导致此。

The first one is when something wrong is written in config.php on line 17 $config['base_url'] = ''; 第一个是在第17行的config.php写错了$config['base_url'] = ''; - it better be left empty, just like when you download CI. -最好将其留空,就像下载CI一样。

The second one is if you have set $config['base_url'] value to something without prefixing it with http:// or other protocol. 第二个是如果您将$config['base_url']值设置为某些值,而没有使用http://或其他协议作为前缀。

The third one is if you have set base href somewhere: 第三个是如果您将base href设置在某处:

<base href="http://www.mysitedomainname.com/" />

When you need to link to some other page, you should use site_url() , base_url() can be used to link stylesheets, js, img src attributes and other real URL's. 当需要链接到其他页面时, 使用site_url()base_url()可用于链接样式表,js,img src属性和其他实际 URL。 The reason is pretty simple, base_url() does not include the index_page value set in config.php . 原因很简单, base_url()不包含config.php设置的index_page值。

如果您使用它将正常工作

<a href="<?php echo base_url('Controller/Function'); ?>">somelink</a>

try this 尝试这个

make this 做这个

$config['base_url'] = "http://www.mysitedomainname.com"

into this 进入这个

$config['base_url'] = ""

in config.php 在config.php中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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