简体   繁体   English

Codeigniter中的BASE_URL显示不同的URL

[英]BASE_URL in codeigniter shows different URL

I have received website code from somebody else & it's giving a lot of errors in loading. 我已经从其他人那里收到了网站代码,并且在加载过程中出现了很多错误。 Every CSS, image or anything is loaded by this code 此代码加载每个CSS,图像或其他任何内容

href="<?php echo asset_url();?>/css/...

Now I checked, asset_helper.php & found out this 现在我检查了asset_helper.php并发现了这个

function asset_url(){
    return BASE_URL.'public'
}

In my config.php , line says $config['base_url'] = ''; 在我的config.php ,行说$config['base_url'] = ''; .

Finally when I tried to echo asset_url(); 最后,当我尝试echo asset_url(); , it gives me https://somerandomwebsite.com/... . ,它给了我https://somerandomwebsite.com/... I'm not sure from where this is coming from. 我不确定这是从哪里来的。

Sorry I'm new to CodeIgnitor & tried everything I could to find out but there was no luck. 抱歉,我是CodeIgnitor的新手,并尝试了所有可能找到的一切,但是没有运气。 Can anybody help me in this? 有人可以帮我吗?

Your Helper function might be using constant function. 您的辅助函数可能正在使用常量函数。 Check your constan.php file. 检查您的constan.php文件。

define(BASE_URL, "http://test.com");

First things first: the manual! 第一件事:手册! https://codeigniter.com/user_guide/helpers/url_helper.html?highlight=base_url#base_url https://codeigniter.com/user_guide/helpers/url_helper.html?highlight=base_url#base_url

ok so they made a new function just to deal with an extra subfolder name in stead of just doing base_url(). 好的,所以他们做了一个新功能,只是处理一个额外的子文件夹名称,而不是仅仅执行base_url()。 'public' or base_url('public') and have defined a BASE_URL somewhere which is not part of the core of CI. 'public'或base_url('public'),并在不属于CI核心的位置定义了BASE_URL。 Track that BASE_URL down and kill it if possible. 跟踪该BASE_URL,并在可能的情况下将其杀死。 You can and should use base_url(). 您可以并且应该使用base_url()。

I use this for base_url (avoids hardcoded url): 我将其用于base_url(避免使用硬编码的url):

$protocol = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https://' : 'http://';
$config['base_url'] = $protocol . $_SERVER['HTTP_HOST'] . str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME']);

I usually autoload the thing in config/autoload.php: 我通常在自动加载的config / autoload.php的事情:

$autoload['helper'] = array('url');

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

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