Borshon saydur rahman
Borshon saydur rahman

Reputation: 130

my base_url is not working although i autoloaded it..why?

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

class user extends CI_Controller

{

    function user()
    {
        $this->view_data['base_url']= base_url();
    }

    function index()
    {
        $this->regester();
    }
    function regester()
    {
        $this->load->view('user_view',$this->view_data);
    }
}

Upvotes: 0

Views: 53

Answers (1)

Damien Pirsy
Damien Pirsy

Reputation: 25445

Try using a proper constructor for php5:

class User extends CI_Controller
{
    private $view_data;

    public function __construct()
    {
        parent::__construct(); // necessary in CI if you declare a constructor
        $this->view_data['base_url']= base_url();
    }
}

For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, and the class did not inherit one from a parent class, it will search for the old-style constructor function, by the name of the class

Since your class is a child of CI_Controller, which has a __construct() method, I believe the method User() in your class isn't being called upon instanciation, and so does base_url()

Upvotes: 1

Related Questions