In config.php
$config['base_url'] = 'http://localhost/codeigniter/';
In View
<link rel="stylesheet" href="<?php base_url(); ?>css/default.css" type="text/css" />
=> Error: Call to undefined function base_url();
Help me
The base URL of the site can be configured in application/config/config. php file. It is URL to your CodeIgniter root. Typically, this will be your base URL, with a trailing slash e.g.
$config['base_url'] = "http://".$_SERVER['SERVER_NAME']."/mysite/"; This configuration will work in both localhost and server.
To use base_url()
(shorthand), you have to load the URL Helper
first
$this->load->helper('url');
Or you can autoload it by changing application/config/autoload.php
Or just use
$this->config->base_url();
Same applies to site_url()
.
Also I can see you are missing echo
(though its not your current problem), use the code below to solve the problem
<link rel="stylesheet" href="<?php echo base_url(); ?>css/default.css" type="text/css" />
I know this is very late, but is useful for newbies. We can atuload url helper and it will be available throughout the application. For this in application\config\autoload.php modify as follows -
$autoload['helper'] = array('url');
You need to load the URL Helper in order to use base_url()
. In your controller, do:
$this->load->helper('url');
Then in your view you can do:
echo base_url();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With