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

#25
(07-10-2016, 10:50 PM)kilishan Wrote:
(07-10-2016, 10:34 PM)prezire Wrote: I'd prefer CI4 to be consistent: Apps\Filters\Auth, Configs\Filter. It's a good thing the entire PHP community didn't follow Java samples like org\somefolder\something, com\somefolder\something.

Unfortunately, I don't think it's possible to standardize quite that far. A common convention that I've seen used many times is that a Controller is plural while the Model is singular. Both of those are classes, so we can't make a general rule. And I get what you're saying about Configs but a) it doesn't sound right to me, and b) other folders also wouldn't be correct as plural, like Database and ThirdParty.

I agree there are some folders that can't be pluralized. It's a good thing though to change them into Databases and ThirdParties Smile

The reason other frameworks pluralize their controllers is because of a convention where they remove the word "Controller". But there's an option for CI4 not to follow this. I've seen a couple years back, other developers tend to create something like Users.php (plural name) instead of UsersList.php (singular name).

Let's say a developer would create a controller for a new Article feature in his app. In most cases, a Laravel developer would create something like ArticlesController.php. The word "Controller" is singular however, since it's their convention to remove that word to shorten the URI, what's left is the word "Articles" hence we get /articles, /articles/{id}, /articles/{slug}. But what most developers don't comprehend much is that "/articles" actually means "/articles/index". If we follow a singular name, it would be "/article/index" just like what Laravel does with its Eloquent inside a controller "\App\Article::all()". The class name is singular, followed by all(), which can be represented via "views/index.blade.php". The same goes for the ID. Pluralized controller name looks a bit odd with "/articles/1" (are there multiple Articles that have IDs of 1?) VS "/article/1".

Yes, these things can be configured via routes, but wouldn't it be nice if the entire CI4 properly practices good plural VS singular conventions for folders and classes by default? But that's just IMO. Hope that helps Smile

Apologies about constantly using Laravel as an example. I have a knack beating that framework in terms of conventions. I get annoyed of other developers constantly saying it's better than CI.
Long live CodeIgniter!
Reply


Messages In This Thread
Controller Filters - Input needed - by kilishan - 07-07-2016, 08:39 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 prezire - 07-11-2016, 05:20 AM
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.