Open xepozz opened 4 years ago
I think it's not the best idea. While base controller might be convenient, I think it's much better to have a set of traits in yii-web
such as ViewRendererConventionTrait
that you can either add to your handler (action, controller) directly or use in your own base controller (if you prefer inheritance).
This controller may be useful in another modules (e.g. yii-debug
, yii-gii
, yii-apidoc
and etc.)
ViewRendererConventionTrait that you can either add to your handler
How will you inject dependencies in this case (e.g. Renderer
, Flash
, UrlGenerator
and etc.)?
Yes, good question.
Overall, idea of base controller is controversial: https://twitter.com/sam_dark/status/1227328185680977921
To me, it's convenient and I don't see any critical drawbacks despite it being formally not correct.
And what's the solution? We can create it, but user will decide whether to use it.
I think the abstract controller should be in the app template. There is no need to move it to the yii-web package.
I think that the controller sould be moved, but not now. The controller is not yet complete. When he ceases to be a draft and finds a stable state, then he will have to be transferred I also hope that we will have several for different tasks.
Yes, we can wait with this one.
Another possibility from that Twitter thread is to wrap view-resolving into its own class and inject it as a dependency i.e. ControllerView that decorates WebView and adds automatic view path resolving.
I'm for having AbstractController
in app templates, that will allow to have different (specialized) AbstractController
s in each template with right dependencies for each case (e.g. ApiController doesn't need view injection), and this approach will allow for easier customization of Base (Abstract) controller as it will be directly visible to end users (developers). This will keep framework away from recommending best or better practices for application code directly and just a propose a way to do something in app template and any developer is free to use the template and or build his/her own.
But it is crucial to have an AbstractController in template at least, as some of my beginner developers (in studio I own) were not sure what to do with all this packages and how to render views after using yii2 extensively and AbstractController will just make their lives easier.
@armpogart why do you need AbstractController if a controller can be any Middleware?
That's same discussion I had on Twitter: https://github.com/yiisoft/yii-demo/issues/53#issuecomment-585353951. If we can achieve convenience without abstract controller, that will be ideal. If not — abstract controller isn't that bad.
@roxblnfk I see it just as a convenient quick start abstract parent (with some helpers) for the most frequent use case per app template. As it will be in app-template any dev will be free to just delete it if he/she doesn't intend to use it.
I would rather propose to have some traits with helpers instead of abstract parent but it would be impossible to inject dependencies in that case and create useful helper.
I am sure that many users do not need to configure the controller for themselves at all.
And those who need it will be able to inherit the basic controller and supplement it, or create their own.
Also since the class is abstract, please rename it
AbstractController