2

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?

1 Answer 1

3

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') ?>" />
Sign up to request clarification or add additional context in comments.

4 Comments

For site_url also we have to use this($this->load->helper('url');) code.is it?
Yes. The site_url function is also in the URL helper (ellislab.com/codeigniter/user-guide/helpers/url_helper.html).
Hello when i added the above code you have given newly created menu class file is not loading ...
I'm not sure what the menu class file is, but I did notice looking at your screenshot that you have css files inside the application folder. Any files that need to be accessible via URL need to be in the document root -- the same folder that contains index.php.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.