• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Undefined variable: base_url

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'] = 'http://somedomain.com/folder/'; <--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 "http://somedomain.com/folder/" ?>
<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"
"Make it idiot proof and someone will make a better idiot."

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.