B
B
Bright2013-04-16 09:54:36
Yii
Bright, 2013-04-16 09:54:36

[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

2 answer(s)
A
Alexander Veliko-Ivanenko, 2013-04-16
@Bright

yiiframework.ru/forum/viewtopic.php?f=8&t=1281

D
duke_nu, 2013-11-24
@duke_nu

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 question

Ask a Question

731 491 924 answers to any question