CodeIgniter creating MY_Controller
Solution 1
Double check the case on your class name and file name.
class MY_Controller extends CI_Controller
Notice how MY_
is all upper-case. Make sure this file is saved as application/core/MY_Controller.php
, again note the case.
CodeIgniter should auto-load this file for you.
Docs: https://www.codeigniter.com/user_guide/general/core_classes.html
P.S. Check the $config['subclass_prefix']
option in your application/config/config.php
file.
Solution 2
You don't need the autoloading functionality. Codeigniter will automatically load My_Controller as long as it's in your application/core directory.
Zeljko Kovacevic
Updated on June 15, 2022Comments
-
Zeljko Kovacevic almost 2 years
How can i create MY_Controller. Where is right place to put this file, i put it in core, folder, and i add into autoload file code
function __autoload($class) { if(strpos($class, 'CI_') !== 0) { @include_once( APPPATH . 'core/'. $class . EXT ); } }
then i created MY_Controller
class My_Controller extends CI_Controller { public function __construct() { parent::__construct(); $this->load->view('view_header'); $this->load->view('includes/nav_home'); $this->load->view('view_home'); $this->load->view('view_footer'); } }
but i keep getting error
Class 'MY_Controller' not found in C:\wamp\www\vezba\application\controllers\pages.php on line 4
i called MY_Controller in file
class Pages extends MY_Controller { function __construct() { parent::__construct(); } }
Where could be problem??