0

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?

2
  • Study the approach used here : github.com/trntv/yii2-starter-kit Commented Jan 31, 2016 at 6:45
  • Create separate controller otherwise you have to put extra security checks in your controller. Commented Jan 31, 2016 at 19:29

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.