I want to make complex modular application with Yii2 which will have frontend and admin section.
I consider to options:
Advanced application template.
For example let say that I want to create comments module, and users should be able to post comments on posts, images, news, products and similar(each of those should be separate module).
Now I should create comment module in common directory, but how about frontend and backend application? Should I create same module in frontend/backend, just with different files(at least I will need to have controller and views for both applications). Is this the best approach approach, or there is better way?
using custom application layout based on basic application layout(I know that I will need to modify many things here, adding separate config files, separate web directory, assets and so on), with module structure like this:
So, can you please suggest best way for this kind of application. I know Yii2 is still in beta, but this is long term project, without deadlines, so I am considering Yii2 only.
Well, almost all models will be shared by both frontend and backend application. The problem are controllers, views which would be different for each application, and in that case I don’t see how I could manage modules easy way(without having same module under common directory and frontend and backend application).
You exactly seem to have a structure. You can define a module with models, components and other common classes in common folder - that you can refer across.
As to controllers and views, you may want to explore:
[*]scenario 1: create them separately for frontend and backend and point your menu links and configure urlmanager accordingly. In your controller/views - you can refer common classes like common\modules\models\ClassName .
[*]scenario 2: you feel you have a lot of reusable Controller code that you can relegate within the module - then you may want to either extend a base controller from backend/frontend OR … just reconfigure module level Controller configuration to call a specific layout or view from backend or frontend based on user access rules.
Extending from a basic app - you would not have the separation of a frontend and backend (like separate apps). Since you mentioned you need a complex commenting module app. it may need separate UI & validations for admin and separate UI and validations for user frontend (for the same data set). If that’s the case, it maybe better IMHO if you use the advanced app.
Thank you for your reply, you are right, forms and model validation rules can be different for frontend/backend, it it would be mess to keep different rules/forms for backened/frontend That was key point