Codeigniter, php5, Fatal error: Class 'Controller' not found
Fatal error: Class 'Controller' not found in <local_path>\system\application\controllers\welcome.php
on line 3
<?php
class Welcome extends Controller {
function __construct()
{
parent::Controller();
}
function index()
{
$this->load->view('welcome_message');
}
}
/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */
I am beginner in php frameworks jus开发者_运维技巧t extracted the CodeIgniter zip file and tried to run welcome.php controller in Aptana studio. ( PHP 5 )
No need to define constructor of class. This is the code for codeigniter 2.0 or later framework.
class Welcome extends CI_Controller {
public function index()
{
$this->load->view('welcome_message');
}
}
the problem was that I am accessing this file directly (like what 'treeface' said), but using this route generates page not found?
127.0.0.1:8000/test_ci/index.php/welcome
then I installed WAMP and used
localhost/test_ci/index.php/welcome
and this is working!
sorry for the inconvenience!
Because you are using the code for the older version of CodeIgniter so use this:
class Hello extends CI_Controller
{
var $name;
var $color;
function Hello()
{
parent :: __construct();
$this->name = "Name";
$this->color = "red";
}
function you()
{
$data["name"] = $this->name;
$data["color"] = $this->color;
$this->load->view("you_view", $data);
}
}
extend CI_Controller instead of Controller I was having the same problem in code ignitor before I switched to CI_Controller
It seems like you have Codeigniter in a different folder than '/'. If you don't change the BASEPATH or system root path in index.php or config.php, that will lead to problems.
Check lines 14-26 (?) in index.php for the "system" variable.
/*
|---------------------------------------------------------------
| SYSTEM FOLDER NAME
|---------------------------------------------------------------
|
| This variable must contain the name of your "system" folder.
| Include the path if the folder is not in the same directory
| as this file.
|
| NO TRAILING SLASH!
|
*/
$system_folder = "system";
Change that to reflect the path of your system folder and CI will surely find your controller class.
精彩评论