0

I'm trying my new hand at Code Igniter and have this issue come up.

( ! ) Fatal error: Class 'Controller' not found in C:\wamp\www\kowmanager\system\application\controllers\user.php on line 2 Call Stack

Time Memory Function Location

1 0.0007 695640 {main}( ) ..\index.php:0 2 0.0021 782824 require_once( 'C:\wamp\www\kowmanager\system\core\CodeIgniter.php' ) ..\index.php:201 3 0.0181 1938352 include( 'C:\wamp\www\kowmanager\system\application\controllers\user.php' ) ..\CodeIgniter.php:248

<?php
class User extends Controller {

function User() 
{
    parent :: Controller();
    $this->view_data['base_url'] = base_url();
}

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

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

}
?>

EDIT:

I changed the class User extends CI_Controller but now I'm getting this:

Fatal error: Call to undefined method CI_Controller::Controller() in C:\wamp\www\kowmanager\system\application\controllers\user.php on line 6

Edit 2:

Here is my new code. Im getting Fatal error: Call to undefined method CI_Controller::User() in C:\wamp\www\kowmanager\system\application\controllers\user.php on line 6

<?php
class User extends CI_Controller {

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

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

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

}
?>
Jeff Davidson
  • 1,921
  • 7
  • 36
  • 60

4 Answers4

1

The userguide uses this line:

class User extends CI_Controller {

Don't have quick access to my CI files at the moment, but I'd go with what the userguide says.

Zomxilla
  • 467
  • 1
  • 4
  • 9
1

check this link. Codeigniter constructors. What is the difference?

It seems you are using CodeIgniter 2+ and PHP 5. With which the old constructor method no longer works.

Ah, since I think you are using PHP 5.

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

You should use __construct() instead.

function User() 
{
    parent::__construct();
    $this->view_data['base_url'] = base_url();
}

Or replace the function name also so it's much readable as overriding the parent constructor method.

function __construct() 
{
    parent::__construct();
    $this->view_data['base_url'] = base_url();
}
Community
  • 1
  • 1
ace
  • 7,293
  • 3
  • 23
  • 28
1

This is the code for the constructor

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

instead of your function user()

Also,

class User extends CI_Controller
looneydoodle
  • 369
  • 6
  • 26
  • 1
    Okay, edited. The constructor has to be __construct in the new version. – looneydoodle Aug 11 '11 at 04:03
  • 1
    Also, tank auth might be a much better way to go. – looneydoodle Aug 11 '11 at 04:05
  • Do I need to do this with models as well? – Jeff Davidson Aug 11 '11 at 14:39
  • When I change class User extends CI_Controller { function User() to class User extends CI_Controller { function __constructor() then I get a A PHP Error was encountered Severity: Notice Message: Undefined property: User::$view_data Filename: controllers/user.php Line Number: 29 A PHP Error was encountered Severity: Notice Message: Undefined variable: base_url Filename: views/view_register.php Line Number: 13 errors – Jeff Davidson Aug 11 '11 at 18:48
  • @looneydoodle let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/2382/discussion-between-jeff-davidson-and-looneydoodle) – Jeff Davidson Aug 11 '11 at 18:48
0

The problem was that I should have taken out the $baseUrl variable for my form open tag.

Jeff Davidson
  • 1,921
  • 7
  • 36
  • 60