• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Writing Admin/User/Public controllers to insure authentication

#7
Honestly, I think that when it comes to modifying the controller hierarchy in a CI application, almost anything is going to, eventually, become a bit hackish.

Bonfire uses Wiredesignz Modular Extensions/HMVC. When I originally started using it, all of the base controllers for Bonfire were defined inside the MY_Controller.php file. In the last couple of years, those controllers have been split up into their own files within the application/core directory (at the moment I don't remember whether this required a modification to the loader). In our case, the class hierarchy for the controllers looks something like this:

- MX_Controller (MX/HMVC - /application/third_party/MX/Controller.php)
- Base_Controller extends MX_Controller (/application/core/Base_Controller.php)
- Front_Controller extends Base_Controller (/application/core/Front_Controller.php)
- Authenticated_Controller extends Base_Controller (/application/core/Authenticated_Controller.php)
- Admin_Controller extends Authenticated_Controller (/application/core/Admin_Controller.php)

Then each controller in a given application usually extends Front_Controller, Admin_Controller, or Authenticated_Controller, depending on the requirements for that controller. In rare cases I've written controllers which extend either Base_Controller or MX_Controller itself, but those usually handled lower level functionality on the site.

The MX_Controller is itself quite a hackish bit of code to overload the controller and loader in CI, and it adds some weight and functionality that you probably aren't really looking for in this case.

In terms of best practices, if I were to implement something from scratch I would probably look into overloading the loader to allow me to load base controllers from the controllers directory. After dabbling in the guts of the loader and MX_Controller a few times, though, I really don't know how long I'd remain interested in doing it myself.
Reply


Messages In This Thread
RE: Writing Admin/User/Public controllers to insure authentication - by mwhitney - 12-30-2014, 03:53 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.