简体   繁体   中英

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

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

Now I checked, asset_helper.php & found out this

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

In my config.php , line says $config['base_url'] = ''; .

Finally when I tried to echo asset_url(); , it gives me 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. Can anybody help me in this?

Your Helper function might be using constant function. Check your constan.php file.

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

ok so they made a new function just to deal with an extra subfolder name in stead of just doing base_url(). 'public' or base_url('public') and have defined a BASE_URL somewhere which is not part of the core of CI. Track that BASE_URL down and kill it if possible. You can and should use base_url().

I use this for base_url (avoids hardcoded 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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