Inheriting a Base Controller In CodeIgniter
So sometimes you want to have a base controller class where you can store common methods through out all your controllers. Here’s how you do it.
Writing the Inheritable Controller
All you need to do is write the file
Then you should should write separate controllers depending on your methods, for example I will write
Auto-loading the Controllers
We need to ammend
config.php to include all the controllers in the
application/core directory. Note that means all these controllers will be loaded you will fallout of CodeIgniter conventions if you do so. Make sure you absolutely need these core functions or else you’ll be loading in garabe you don’t need on every request.
Lastly, you need to actually use your new extended controller!