5

I have already loaded the URL helper, I have set the base url in config, yet this code seems to gave me:

PHP Error was encountered

Severity: Error

Message: Call to undefined function base_url()

Filename: views/site_navigation.php

Line Number: 6

Here is line number six:

<li><a href="<?php echo base_url(); ?>/welcome">Home</a></li> 
Kevin
  • 41,694
  • 12
  • 53
  • 70
KGdB
  • 59
  • 1
  • 5

6 Answers6

5

This error means only one thing that you did not load the url helper correctly. Please follow the documentation and load it as specified from your current action or from the constructor of your controller.

SaidbakR
  • 13,303
  • 20
  • 101
  • 195
2

When you need to use the base_url(); or config_item('base_url') or $this->config->item('base_url')

First example:

public function __construct() {
    parent::__construct();
    $this->load->helper('url');
}

Or

public function index() {
   $this->load->helper('url');
}

Second Example:

Go to application / config / autoload.php

And add the url to here which I think is best for you.

$autoload['helper'] = array(
    'url',
    'file',
    'form',
    'text',
    'html',
    'date'
);

Now go to the application / config / config.php Find $config['base_url'] = '';

Enter your base url example http://www.example.com/ or http://localhost/project/

  • $config['base_url'] = 'http://www.example.com/'; Recommended include forward slash at end
  • $config['base_url'] = 'http://localhost/project/'; Recommended include forward slash at end

If you need to remove the index.php find htaccess examples here

Download htaccess for codeigniter Git hub

Codeigniter User Guides

Codeigniter User Guides For Version 2 & 3 Can Be Found Here

Once all that is done

<li><a href="<?php echo base_url(); ?>">Home</a></li>

This will get you to the default home page

1

If you are using CI 2.0.0 (in line number 67)

$autoload['helper'] = array('url');

or else if you are using CI 3.0.0 (in line number 91)

$autoload['helper'] = array('url');

in addition

Assign these empty

$config['base_url'] = '';
$config['index_page'] = '';
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

base_url() is a function of the object config Try this: <li><a href="<?php echo $this->config->base_url(); ?>/welcome">Home</a></li>

Sergio Vilchis
  • 332
  • 2
  • 4
  • 16
  • This brings up the right url in the address bar, however it still comes up with This web page is not available ERR_NAME_NOT_RESOLVED – KGdB Apr 30 '15 at 01:42
  • whereas if i just type the url without navigating through the link, the page works fine – KGdB Apr 30 '15 at 01:43