Answer the question
In order to leave comments, you need to log in
What is the best way to organize the structure of the bulletin board?
Hello. I ask people who know the mvc pattern and, in particular, yii2 people to help with the correct organization of the application (a message board with many categories, where each category has subcategories).
Please explain how to do it correctly using the example of one category, for example, "Transport" with subcategories "Motorcycles" and "Cars":
I'm going to organize the database in this way - a separate table for the "Transport" category, where there will be both motorcycles and cars, as well as two separate tables for each of the subcategories. That is, in this example there will be only three tables. The site should have three different pages: 1 - where all vehicles are displayed with the appropriate filters, 2 - only cars with their specific filters, 3 - motorcycles with their own filters. Q: Do I need to create 3 controller/model/view sets - 1 for category and 2 for subcategories? Or is there a better way to do something like this? I would be very grateful for any recommendations and educational program.
Answer the question
In order to leave comments, you need to log in
It depends on the TK. If the table structure and interfaces are different, then the controller-model-view will be different. If similar, then one set of mvc is enough.
In my opinion, the table for cars and motorcycles is largely the same: manufacturer, year of manufacture, engine size, power, price, etc. So, one table is enough. Moreover, there will be a page "all transport".
The controller and the view are also probably one at a time. But in some cases, you can make 2 actions, in which there will be different logic, and the general one is placed in a private method.
Categories should be stored in a separate table according to the Nested Set principle, thus the issue of multiple nesting will be solved. (yii2 seems to have a solution for working with Nested Set)
Next, a table with vehicles, cars, motorcycles all together, if one element can have one category, then in this de table we create a column with a category, if not, then a separate table for transport links and categories. Also in this table we create columns only for common fields, such as name, date of manufacture, power, etc.
All attributes that are not common can be organized according to the EAV principle, that is, you create an attribute yourself, assign it to a category, and fill in for each element of the category given attribute.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question