2

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

3 Answers 3

13

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.

Sign up to request clarification or add additional context in comments.

2 Comments

i put this files in system core not aplication core
You shouldn't be modifying the system folder. That's why application/core exists. So you can extend/replace files without touching the system files.
4

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

Comments

0

You don't need to autoload your class, the framework will do it for you. In your case check the config file whether the subclass_prefix is 'MY_'. Eg; $config['subclass_prefix'] = 'MY_'; Put your class in application/core. Make sure the class name and the file name is the same.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.