hairynuggets
hairynuggets

Reputation: 3311

Extending codeigniters controllers

I have a controller called 'admin'

class Admin extends CI_Controller {

and under the admin controller I want to have a series of controllers like:

class Settings extends CI_Controller {
class Preferences extends CI_Controller {

Is it possible to have these controllers extend the Admin controller?

like

class Settings extends Admin {

Is it possible?

Upvotes: 0

Views: 72

Answers (1)

Quetzy Garcia
Quetzy Garcia

Reputation: 1840

Yes, it is possible. You just have to create your extended controller in the /core/ directory of your application, like so:

class MY_Controller extends CI_Controller
{
...
}

Then, you can create controllers that extend MY_Controller in the /controllers/ directory of your application, like so:

class SomeClass extends MY_Controller
{
...
}

Pay attention to the class and file naming convention.

Read more about it in the CodeIgniter User Guide, on how to extend the Core.

Upvotes: 3

Related Questions