M
M
miy2015-03-04 18:47:18
Yii
miy, 2015-03-04 18:47:18

Where to store application business logic in Yii2?

There are 2 types of models in Yii2: Active Record and form model.
In which type of model should the application logic be stored?
Or is it better to add a separate service layer and store the logic there?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Egor Mokeev, 2015-03-04
@miy

Since ActiveRecord tends to be regenerated during development, it is better to move the business logic into a separate model.
There is also such a balalaika as yii2-giix, which separates the model into a base model and a wrapper in which business logic is written. Not the best solution, but may speed up development.
And yes, in yii2 there is no form model, there is just a Model

S
Sergey, 2015-03-04
@butteff

Why can't the logic be handled in the controller?
For example, there is a form model, where we describe it, create validation rules.
There is a controller that renders the desired view, to which the form model is passed.
The user sees the view and enters data in the form, they go to the controller.
There (in the controller) I process the logic, depending on the received data, either I render something on the screen again, or I do other things (there can be anything - writing to the database, calling some function or method, etc.)
Is this getting wrong in terms of MVC canons?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question