Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter creating MY_Controller

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??

like image 415
Zeljko Kovacevic Avatar asked Dec 04 '25 13:12

Zeljko Kovacevic


2 Answers

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.

like image 81
Rocket Hazmat Avatar answered Dec 07 '25 03:12

Rocket Hazmat


You don't need the autoloading functionality. Codeigniter will automatically load My_Controller as long as it's in your application/core directory.

like image 31
twistedpixel Avatar answered Dec 07 '25 04:12

twistedpixel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!