A
A
agent11562016-09-12 22:53:17
Yii
agent1156, 2016-09-12 22:53:17

How to work with activeFom in yii 2?

Tell me how to do it right. In the form I receive data from the form, they are loaded into the controller. I need to set a default inputText value and add the data received from the form to it.
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->images = 'Default!!!!' + data received from the form
How ?
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2016-09-13
@mhthnz

If you need to change the value, then validate and save:

if ($model->load(Yii::$app->request->post())) {
    $model->images = 'some value' . $model->images;
    $model->save()) {
        //Save logic
    }
}

If you need to validate and change the value before saving, then:
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
    $model->images = 'some value' . $model->images;
    $model->save(false)) {
        //Save logic
    }
}

R
Rou1997, 2016-09-12
@Rou1997

$model->images = 'Значение по умолчанию!!!!' . $model->images;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question