A
A
Alexander2015-10-25 18:42:06
Yii
Alexander, 2015-10-25 18:42:06

Business logic and model parameters in yii?

Interested in the opinion of how best to build model methods in yii.
There are many examples where they do something like this:

$model->a = $_POST['Model']['a'];
$model->b = $_POST['Model']['a'];
и тд.. либо через массовое присовение $model->attributes = $_POST['Model];
и потом вызов:
$model->create();

Or make input parameters in the create method and work with assigning attributes already inside the method:
$model->create($_POST['Model']['a'],$_POST['Model']['b']);
Внтури уже метод:
function create($a,$b)
{
 $this->a = $a;
 $this->b = $b;
 return $this->save();
}

The second way seems to be more correct because we know exactly what parameters are needed for the method. In the first method, you can't tell right away.
Who is building?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pantsarny, 2015-10-25
@pantsarny

Yii2? Then the ActiveRecord->load()
Yii1 method? ActiveRecord->attributes = $_POST['data']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question