Answer the question
In order to leave comments, you need to log in
How to deal with dependent data in the controller?
Let's say there are two ActiveRecords
1. Describing the table of brands (brand) with the structure
- id
- name
2. Describing the table of products (product) with the structure
- id
- name
- brand_id
There is a page for adding products on which the user enters the name of the product and selects the appropriate brand from the select .
Actually the question is: where should I create a list of brands for the select? in the controller and push it through all the necessary views? But then it turns out that the controller responsible for the operation of the goods will depend on AR brands, which seems to be not very good either. And if there are 10 such dependencies, then the controller will become very bold and turn into a bunch of dependencies ... what to do?
PS this is just an example to convey the essence of the issue, I'm interested in ways to solve such situations
Answer the question
In order to leave comments, you need to log in
Good afternoon.
The method that will be responsible for the withdrawal of brands, write in the brand model.
In the view, you can access it like this:
In the brand model, the method might look like this:
public static function addBrandName()
{
// тут запрос к базе на получение всех названий брэндов
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question