Question

I am new in CodeIgniter. In my project, the base URL code is not working properly...

In config.php:

$config['base_url'] = 'http://localhost/simpleblog/';

In view, it is:

<link type="text/css" rel="stylesheet" href="href="<?=base_url()?>views/css/Main.css" />

My Project File Structure was attached in skydrive https://skydrive.live.com/redir?resid=3BFF708C7026EB1B!139&authkey=!AEQSh3KwTzDU328&v=3

And also the error

https://skydrive.live.com/redir?resid=3BFF708C7026EB1B!140&authkey=!AMwGc_UWpqlezOM&v=3

How do I solve this issue?

Was it helpful?

Solution

The base_url function is part of the URL helper. CodeIgniter does not load any helpers by default, so you must load the helpers you want to use.

You can either do this in the controller where you'll be using the function:

$this->load->helper('url');

Or if it's a helper you intend to use throughout the site, you can tell CodeIgniter to automatically load it by adding it to the $autoload['helper'] array in config/autoload.php.

BTW - for this use case, I recommend site_url() instead of base_url():

<link type="text/css" rel="stylesheet" href="<?= site_url('views/css/Main.css') ?>" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top