Welcome Guest, Not a member yet? Register   Sign In
Recommended practice for applying actions common to all controllers
#1

[eluser]Andy UK[/eluser]
I just wanted to check with fellow forum members what the recommended practice is for applying actions to all controllers.

I think what I should be doing is extending the base class with a MY_Controller, place my code in there and then in each controller extend MY_Controller instead of CI_Controller.

Is this considered the right way to do things?

For example, I want to check certain environment variables are set before running any controller and if not, set them there.

Cheers!
#2

[eluser]Andy UK[/eluser]
To answer my own question, it would appear that this is the correct way to do it. I found the following post by Phil Sturgeon for those who are interested...

http://philsturgeon.uk/blog/2010/02/Code...ing-it-DRY
#3

[eluser]CroNiX[/eluser]
Yes, using MY_Controller is the way to do that. You may or may not need to go the extra mile that Phil describes by creating multiple base controllers depending on the complexity of your app. But CI has MY_Controller functionality built in. You just need to create one and have all other controllers extend MY_Controller instead of CI_Controller.




Theme © iAndrew 2016 - Forum software by © MyBB