Welcome Guest, Not a member yet? Register   Sign In
Call to undefined method CI_Controller::Controller()
#1

[eluser]Unknown[/eluser]
Fatal error: Call to undefined method CI_Controller::Controller() in D:\xampp\htdocs\myfirstcodeigniter\application\controllers\user.php on line 6
Hello, I am using CodeIgniter 2.0 and I am new to the framework. I tried extending the CI_Controller class and it is not works for me on my computer using xampp.

<?php
class User extends CI_Controller {

function User()
{
parent::Controller();
$this->view_data['base_url'] = base_url();
}
function index()
{
$this->register();
}
function register()
{
$this->load-view('user_view', $this->view_data);
}
}
?>
#2

[eluser]TWP Marketing[/eluser]
[quote author="pangit" date="1302046407"]Fatal error: Call to undefined method CI_Controller::Controller() in D:\xampp\htdocs\myfirstcodeigniter\application\controllers\user.php on line 6
Hello, I am using CodeIgniter 2.0 and I am new to the framework. I tried extending the CI_Controller class and it is not works for me on my computer using xampp.
Code:
<?php
class User extends CI_Controller {

        function User()
        {
            parent::Controller();
            $this->view_data['base_url'] = base_url();
        }
        function index()
        {
            $this->register();
        }
        function register()
        {
            $this->load-view('user_view', $this->view_data);
        }
}
?>[/quote]

Ver 2.0.1 is the latest and the User_Guide specifies the use of "__construct" as the constructor function name, NOT the controller name as was the case in prior versions (1.7x and earlier).
This is to conform with PHP 5.
Code:
<?php
class User extends CI_Controller {

function __construct() <-- new function name
{
  parent::__construct(); <-- new constructor call
  $this->view_data['base_url'] = base_url();
}

function index()
{
  $this->register();
}

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




Theme © iAndrew 2016 - Forum software by © MyBB