开发者

Working on a registration controller with CI

开发者 https://www.devze.com 2023-03-27 12:09 出处:网络
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

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);
}

}
?>


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();
}


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消