Hello! I have some questions about class name convention in Yii2 core.
Why is it incossistent?
\yii\behaviors, \yii\controllers, \yii\validators have all their classes postfixed with type 'Behavior,Controller,Validator`
\yii\filters instead does not have Filter postfix.
\yii\helpers and \yii\widgets have classes following both conventions. Some of them have postfixes and some do not. yii\helpers\Url and yii\helpers\FileHelper are the examples.
I can’t see the reason for this inconsistency and would be glad to hear some clarification
Why does Yii2 force the user to name all controllers with a Controller postfix? What is the rationale behind this? What is strange is that from my point of view this is not needed for the framework to process requests in any way. Yii just should find the FooBar file with FooBar class in controllers directory for the foo-bar/baz-quux request path. That is also an inconsistency since this is (as far as I know) the only limitation of that kind in the whole framework. E.g. you are not forced to name widgets and actions with postfixes.
As a result it is hard to decide how to name my application classes, e.g. actions and widget. Do I add Action and Widget postfix or no? Either way would result in the inconsistent convention.
actionIndex vs indexAction is very handy i.e. in the code you can quickly identify what’s action and what’s just a method. I’m OK with other frameworks naming but I like Yii’s naming better. Probably it’s personal preference.
Allowing to customize it sounds kinda wrong to me. First it will introduce inconsistency among Yii apps and second it’s among critical execution path. The more customizations among the flow the less performance we get.
When i started using Yii many years ago, migrating from kohana (action_dosomething) I didn’t bother too mutch. But after using other frameworks my mind always automatically searches at the end of the name for Controller, Action etc etc. So i guess it’s really a matter personal preference and experience.
Maybe just moving that code fragment into a separate method (smt like resolveActionMethod($id)). It will be called once per request. In this way a user can just override it in his own base project controller instead of the whole createAction (as i am doing right now).
Yeah, that’s just a personal preference. I don’t think it’s a good idea to change framework convention in this case since new team members will be confused.