Welcome Guest, Not a member yet? Register   Sign In
Constructor error?
#1

[eluser]Hamed[/eluser]
I use one of website tutorial and now I get error on constructor:


Fatal error: Call to undefined method CI_Controller::Controller() in C:\wamp\www\application\controllers\main.php on line 5

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Main extends CI_Controller {
    public function Main() {
        parent::Controller();
    }
public function index()
{
    $query = $this->db->query('');
    $this->load->view('main/index');
}
}
#2

[eluser]CroNiX[/eluser]
It must be outdated. We use php5's __construct() for constructors now.

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Main extends CI_Controller {
  //The constructor
  public function __construct() {
      parent::__construct();
  }
  public function index()
  {
    $query = $this->db->query('');
    $this->load->view('main/index');
  }
}

But the main error you are seeing is because you used "parent::Controller();" instead of "parent::CI_Controller();", but that's moot if you use the new construct above. Please see the user guide for Controllers (this is mentioned at the bottom)




Theme © iAndrew 2016 - Forum software by © MyBB