Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transfer base controller to the yii-web package #53

Open
xepozz opened this issue Feb 9, 2020 · 11 comments
Open

Transfer base controller to the yii-web package #53

xepozz opened this issue Feb 9, 2020 · 11 comments
Labels
status:ready for adoption Feel free to implement this issue.

Comments

@xepozz
Copy link
Contributor

xepozz commented Feb 9, 2020

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

@samdark
Copy link
Member

samdark commented Feb 12, 2020

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).

@xepozz
Copy link
Contributor Author

xepozz commented Feb 12, 2020

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.)?

@samdark
Copy link
Member

samdark commented Feb 12, 2020

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.

@xepozz
Copy link
Contributor Author

xepozz commented Feb 13, 2020

And what's the solution?
We can create it, but user will decide whether to use it.

@yiiliveext
Copy link
Contributor

I think the abstract controller should be in the app template. There is no need to move it to the yii-web package.

@roxblnfk
Copy link
Member

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.

@samdark
Copy link
Member

samdark commented Feb 13, 2020

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.

@armpogart
Copy link
Contributor

I'm for having AbstractController in app templates, that will allow to have different (specialized) AbstractControllers 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.

@roxblnfk
Copy link
Member

@armpogart why do you need AbstractController if a controller can be any Middleware?

@samdark
Copy link
Member

samdark commented Feb 22, 2020

That's same discussion I had on Twitter: #53 (comment). If we can achieve convenience without abstract controller, that will be ideal. If not — abstract controller isn't that bad.

@armpogart
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready for adoption Feel free to implement this issue.
Projects
None yet
Development

No branches or pull requests

5 participants