Answer the question
In order to leave comments, you need to log in
[Yii] How to work with several similar entities stored in one table?
Good afternoon.
The initial data is as follows: the site has several identical entities - Page, Promotion, Question. The only difference is how they should be displayed + promotions and questions have a small picture and a short text description (required fields; they are not required for pages). Because otherwise they are similar, then in the database you can create one page table for them.
But the question arises of how to deal with models, controllers and how to properly configure routing.
The address structure is as follows:
example.com/specials/ - list of stocks
example.com/questions/ - list of questions
example.com/question/{title} - question page
example.com/{title} - any other page
Would it be correct to use one model and one controller for all three entities (and already in the code, depending on the type, make checks for filling in the required fields)? Or is it more correct to create a separate model and controller for each type of entity (in this case, the code will be slightly duplicated, but the routing rules will be simplified)?
Answer the question
In order to leave comments, you need to log in
If the data is stored in one table, it is better to use one model. You can split the validation using the Form Validation scripts . Regarding actions, if you have 3 controllers for each type, then it is better to place form processing with different scenarios in each controller type.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question