• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Controller Filters - Input needed

#2
Thanks for the thread.

Just to reiterate some of what I said on Git.

Rails filtering system is great in some aspects. It allows you to easily set rules for controllers and you can also tell it to only work on certain methods or ignore other (:only if I remember correctly). The issue with this that my teams always ran into was maintainability as the application grew.  The larger the application became, the more difficult it was to keep track of which routes/controllers/actions had certain filters. Compound that with classes which are extending other classes which have filters and the problem could quickly become a nightmare with cascading rules and so on.

The 'problem' with codeigniter is that the routing system is not required, meaning that a middleware system such as laravels would not work. 

Looking at an application as a whole, it would make more sense for most filters to be placed somewhere before a controller. Not only does this help eliminate any dependency the filter might create on the controller (I think), it allows for the developer to access filters/middleware in a single file elsewhere which in the end will be much easier to maintain. 

If we take the Rails example (http://guides.rubyonrails.org/action_con...ml#filters), they use the `before_action :require_login` as an example. Now lets say we have 50+ controllers that require some form of authentication. That would mean we'd have to make sure that all 50 controllers have that piece of code, which goes against DRY in my opinion. Then lets say that 25 of those controllers need some other form of authentication like an admin role. You could then create another filter, and add them to the admin controllers. Now lets imagine that there are 5 different type of admin roles, and each role might have access to a certain controller, or multiple controllers. And on top of that, let's add that a few of those controllers need to support CORS. All of a sudden you have multiple filters which are being individually set at the controller level, which may or may not specify a certain action.

As you can imagine in the above example, this leads to harder to maintain code.

I would propose a filter/middleware system where you could have a single file to declare your filters and where they would be attached. Whether this happens in the routes.php file or not doesn't matter, but I believe that having that file would be much cleaner and more maintainable than the filter system that Rails currently uses. Is it possible to have CI4 check the routes.php file for middleware/filters even if auto-routing is enabled? Is it possible to have a filters config files?
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply


Messages In This Thread
Controller Filters - Input needed - by kilishan - 07-07-2016, 08:39 PM
RE: Controller Filters - Input needed - by albertleao - 07-07-2016, 09:06 PM
RE: Controller Filters - Input needed - by arma7x - 07-10-2016, 06:46 AM
RE: Controller Filters - Input needed - by arma7x - 07-07-2016, 09:14 PM
RE: Controller Filters - Input needed - by arma7x - 07-10-2016, 11:42 PM
RE: Controller Filters - Input needed - by arma7x - 07-12-2016, 01:55 AM
RE: Controller Filters - Input needed - by arma7x - 07-13-2016, 12:23 AM
RE: Controller Filters - Input needed - by arma7x - 07-14-2016, 12:37 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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