Codeigniter.tvbeta

Codeigniter video tutorials and screencasts

Extending the core: MY_Controller and beyond

Author: Joost van Veen

2011/09/15 Screenshot from video tutorial

In this video tutorial we will be looking at MY_Controller, frontend controllers and backend controllers. MY_Controller is a kind of base controller that can contain code which you need access to throughout your entire application. Think of user login checks, latest news to show in your sidebar, and so on.

Then again, sometimes, having a MY_Controller class just doesn't cut it. You may only need a user login check in an admin environment. If that's the case, you can even extend MY_Controller - and thus create a seperate frontend and backend controller, for instance. The sky's the limit, really.

Bottom line: extending the 'classic' CI_Controller can help keep your code clean. It keeps you from having to copy/paste your code through different controllers - ouch! We can all imagine the sheer horror if you ever need to make adjustments to that code!

This is the first tutorial in the series 'extending the core'.

Download the source code for this tutorial (.sql included)