M
M
MIK Ek2018-07-31 09:46:57
Yii
MIK Ek, 2018-07-31 09:46:57

Theoretical question about correct code. How to correctly implement a method ("not action") in the controller within the framework of MVC?

The controller has a method that implements a lot of functionality used in the actions of this controller. (data exchange between some arbitrary models).
This functionality does not logically fit into any specific model.
Logically (in my opinion) it is part of the controller.
Is it right to leave this code in the controller or is it better to take it out somewhere?
The essence of torment:
On the one hand, it seems to be in its place, but on the other hand, it occupies most of the controller, and in principle, is it better that the controller contains only methods (actions) accessible from outside?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Bobkov, 2018-07-31
@mike_bma

Create a service and put "data exchange between some arbitrary models" there.
Name it so that it is clear what kind of exchange is taking place and use it in the controller.

C
Crash, 2018-07-31
@Bandicoot

Feel free to transfer all controller methods that are not actions to helpers, they belong there.
Unless auxiliary methods like findModel can be left.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question