MVC: Structuring the output stream

The structure that I use in my project follows the MVC pattern. I "create JSON channels and you need to structure them differently from what the system gives me by default from ORM. Where should I handle the task of manipulating and generating my data that I will serve in a model, view or controller?

Now I do this in my controller, and then pass this data to the view. I see that this works better under a model or view, but not sure which one.

+3
source share
2 answers

If this other structure is only related to the view, you should keep it in the view. If this structure is used in more than one view, make an assistant for it.

Internally, your application must standardize in a single data format, so models should always return a standardized format. If you have to do something with this data in your controller, you will need to change the logic of interacting with data in only one controller function, which in this case does not make much sense. If you later decide to change the format in the model, you will also need to change the code in the controller that interacts with it. Do not create dependencies if there are no benefits to this.

+1
source

, , . , , , - . , , . , , .

0

Source: https://habr.com/ru/post/1736552/