Guy in the chair
Guy in the chair

Reputation: 1065

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?

Upvotes: 0

Views: 442

Answers (2)

TIGER
TIGER

Reputation: 2907

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

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

Upvotes: 4

qwertzman
qwertzman

Reputation: 782

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');

Upvotes: 1

Related Questions