您如何在YII中接近前端/后端?

I am using YII for the first time, and I just need some general opinions.

If I take, as an example, the User table, and I am going to have users register from the frontend, but I am also going to be managing users from the admin backend, how would you go about it?

Would you create one user controller and use that in both views, or would you create a UserController with its own views and AdminUserController with its own views?

You may not have to necessarily recreate the module in all places. You can just place the module code in the common folder.

1) If your module configuration is same for both frontend and backend - you can register your module in common/config/main.php. This should be available in both frontend and backend.

2) If your module configuration is different for both frontend and backend - you can register your module separately in frontend/config/main.php and backend/config/main.php.

Reference

Generally in advanced yii2 application you have 3 folders(frontend, backend, common) which you can use for storing all the models, controllers, views and so on.

If we need one user model for both backend and frontend parts of the application we need to keep this model in common folder. It will give you opportunity to get all the data in frontend and backend from one common table. In model itself you have to write some methods you will use only on backend (like search by some specific params) and frontend(like voting for user comment etc.).

Generally I have different controllers for backend and frontend(the same for views) and common models for both.

using yii2 advanced you can put common functionality in @common wether its controller or model or whatever.

then inside @backend or @frontend you can extend classes from what is inside @common and add specific functions that suits your needs.

for user functionality, I suggest using dektrium/yii2-user extension, I used it in more than one project and it can save your time. It's well documented too.

try using it.