Msgstr "Not found code_code MY_Controller

im using Codeigniter.2.1.3 for the website, so I need to extend CI_Controller, so I can add a method that will be executed with all controllers, so I did something in user_guide:

by creating a file called MY_Controller.php in the application / core folder, creating a class MY_Controller in it that extends CI_Controller, changing my regular controller to extend MY_controller as follows: MY_controller.php:

class MY_Controller extends CI_Controller{ protected $page; # Constructor function __construct (){ parent::__construct(); #code shared with all controllers } public function get_page(){ #code to get_the right page here } } 

regular controller named Regular.php:

 class Regular extends MY_Controller{ public function __construct(){ parent::__construct(); } public function index(){ $this->get_page(); } } 

but the following error appears:

Fatal error: class' MY_Controller not found in / var / www / immo / CodeIgniter _2.1.3 / application / controllers / regular.php on line 2

+6
source share
4 answers

You will need to enable the MY_Controller class or automatically load it. I suggest you automatically download it by adding the following to your application/config/config.php .

 function __autoload($class) { if (strpos($class, 'CI_') !== 0) { if (file_exists($file = APPPATH . 'core/' . $class . EXT)) { include $file; } } } 
+12
source

Make sure the file name is well-wrapped. The Linux server is case sensitive. Therefore, if the class name is My_Controller, then the file name should be My_Controller.php

+4
source

$ config ['subclass_prefix'] = "MY_" check that in config.php and of course you should use it in the controller name, like MY_Controller.php and named "class MY_Controller ...."

+1
source

Late with this answer, but I got the error "Fatal error: class" MY_Controller not found "when I had a controller (php) file with the same name in the network root and not in the application / controller directory. I don’t know how it turned out, in fact, but the problem disappeared when I deleted it.

0
source

All Articles