CodeIgniter Forums

Full Version: Undefined variable: base_url
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I am getting the following error when trying to use $base_url in a view:

Message: Undefined variable: base_url
Filename: templates/header.php

Message: Function name must be a string
Filename: templates/header.php

From researching this, the most common reason for this is that the 'url' helper has not been loaded but I have added it to autoload.php


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

I have also checked the $base_url variable in config.php:

PHP Code:
$config['base_url'] = ''; <--domain name changed from original 

And this is the php of the view:

PHP Code:
<link href="<?php echo $base_url(); ?>css/bootstrap.min.css" rel="stylesheet"

This is how the view is been loaded from the controller:

PHP Code:
    function index()
        $data['tasks'] = $this->Task_model->get_all_tasks();

If I changed it to use a local variable it works fine:

PHP Code:
<?php $test "" ?>
<link href="<?php echo $test?>css/bootstrap.min.css" rel="stylesheet"> 

I am new to this so it could be something simple but it is although the config file and/or autoload file is not linked in properly, corrupt or been overidden somehow. Any suggestions welcome.
It is simple - it's a function, not a variable (and you're trying to use it as a variable function).
Thanks, yes I spotted my mistake. should be <?php echo base_url() ?> not <?php echo $base_url() ?>.
PHP Code:
<link href="<?php echo $base_url(); ?>css/bootstrap.min.css" rel="stylesheet"

should be

PHP Code:
<link href="<?php echo base_url(); ?>css/bootstrap.min.css" rel="stylesheet"