Welcome Guest, Not a member yet? Register   Sign In
CI3 CI_Controller extending


I would like to create an Api controller extending the basic CI_Controller.
After that I could extend API_Controller to create separate API controllers like users api etc.

I've just read some solutions for older version but that looks strange for my.
For example adding __autoload function to the config.php.

I tried to put MY_Api.php into application/core folder and it doesn't work.

Thanks for the help!

You can name the controller class anything you want, but when saved it has to be saved as MY_Controller in ./application/core
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

You can change the prefix of the file name too, that can be done in ./application/config.php.

So you could save PINGWIN_Controller.php in ./application/core.

one thing you can do to achieve this is something like this:

in: application/core
create: MY_Controller.php

in: application/core
create: Api_controller.php

in: MY_Controller.php your code could look like this:

PHP Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

MY_Controller extends CI_Controller
    public function 
// END MY_Controller class

if ( ! class_exists('Api_Controller'))

/* End of file MY_Controller.php */
/* Location: ./application/core/MY_Controller.php */ 

this way your Api_controller class will be autoloaded with MY_Controller allowing you to extend it in application/controllers just like MY_Controller.
"I reject your reality and substitute my own" - Adam Savage, M5 Inc.

Theme © iAndrew 2016 - Forum software by © MyBB