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

#1
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

/application/config/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();
        $this->load->view('templates/header');
        $this->load->view('task/index',$data);
        $this->load->view('templates/footer');
    


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.
Reply

#2
It is simple - it's a function, not a variable (and you're trying to use it as a variable function).
Reply

#3
Thanks, yes I spotted my mistake. should be <?php echo base_url() ?> not <?php echo $base_url() ?>.
Reply

#4
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."
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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