jeudi 8 mai 2014

CodeIgniter 2.0 Fatal error : Class « Controller » introuvable dans - Stack Overflow


i have download the new codeigniter 2.0 and put my controller,model and view files in the new codeigniter 2.0 installation. but i got this error


Fatal error: Class 'Controller' not found in /Applications/MAMP/htdocs/site/application/controllers/forside.php on line 3


What im doing wrong? it works with the old codeigniter version but the new one.. No :S


Hope some one can help me out




In CodeIgniter 2 your controllers inherit from super class CI_Controller, rather than the super class Controller used in CodeIgniter 1.


The same applies to models in CI2 which extend the class CI_Model rather then Model.




I think you are not extending the controller like below;


<?php
class MyOwnController extends CI_Controller {

function index()
{
// your code here
}
}
?>

It's written on http://codeigniter.com/user_guide/general/controllers.html, you have to extend CI_Controller




class Student extends CI_Controller {

function Student() {
parent::__construct();

// load helpers
$this->load->helper('url');
}
}

Including the parent::__construct(); rather than parent::Controller();




Along with that CI_ prefix to your controller, any core classes you extend, you should place withing the applications/core/ folder. This is because the core CodeIgniter classes have been moved to the system/core/ folder.




Make sure the Controller's name matches the prefix defined in the config:


By default, the config has:


$config['subclass_prefix'] = 'MY_';

If your controller is core/SomeController.php it won't be found because it doesn't start with MY_



i have download the new codeigniter 2.0 and put my controller,model and view files in the new codeigniter 2.0 installation. but i got this error


Fatal error: Class 'Controller' not found in /Applications/MAMP/htdocs/site/application/controllers/forside.php on line 3


What im doing wrong? it works with the old codeigniter version but the new one.. No :S


Hope some one can help me out



In CodeIgniter 2 your controllers inherit from super class CI_Controller, rather than the super class Controller used in CodeIgniter 1.


The same applies to models in CI2 which extend the class CI_Model rather then Model.



I think you are not extending the controller like below;


<?php
class MyOwnController extends CI_Controller {

function index()
{
// your code here
}
}
?>

It's written on http://codeigniter.com/user_guide/general/controllers.html, you have to extend CI_Controller



class Student extends CI_Controller {

function Student() {
parent::__construct();

// load helpers
$this->load->helper('url');
}
}

Including the parent::__construct(); rather than parent::Controller();



Along with that CI_ prefix to your controller, any core classes you extend, you should place withing the applications/core/ folder. This is because the core CodeIgniter classes have been moved to the system/core/ folder.



Make sure the Controller's name matches the prefix defined in the config:


By default, the config has:


$config['subclass_prefix'] = 'MY_';

If your controller is core/SomeController.php it won't be found because it doesn't start with MY_


Related Posts:

0 commentaires:

Enregistrer un commentaire