php – base_url() function not working in codeigniter

php – base_url() function not working in codeigniter

In order to use base_url(), you must first have the URL Helper loaded. This can be done either in application/config/autoload.php (on or around line 67):

$autoload[helper] = array(url);

Or, manually:

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

Once its loaded, be sure to keep in mind that base_url() doesnt implicitly print or echo out anything, rather it returns the value to be printed:

echo base_url();

Remember also that the value returned is the sites base url as provided in the config file. CodeIgniter will accomodate an empty value in the config file as well:

If this (base_url) is not set then CodeIgniter will guess the protocol, domain and path to your installation.

application/config/config.php, line 13

If you want to use base_url(), so we need to load url helper.

  1. By using autoload $autoload[helper] = array(url);
  2. Or by manually load in controller or in view $this->load->helper(url);

Then you can user base_url() anywhere in controller or view.

php – base_url() function not working in codeigniter

First of all load URL helper. you can load in config/autoload.php file and add following code
$autoload[helper] = array(url);

or in controller add following code

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

then go to config.php in cofig folder and set

$config[base_url] = http://urlbaseurl.com/;

hope this will help
thanks

Leave a Reply

Your email address will not be published.