A
A
Andrey Markov2016-05-24 17:33:34
Yii
Andrey Markov, 2016-05-24 17:33:34

Yii2 saving attributes in model?

Hello, the model has an attribute myVar which is stored in Mysql and contains data as a string : '3,4,5,6'. , I can’t figure out why the myVar variable does not change when the model is saved?
Model

...
public function getMyVar(){
  return explode(",", $this->myVar);
}
public function setMyVar($value){
 $this->myVar = implode(",", $value);
}
...

_form.php
...
$form->field($model, 'CreditSecurity')->dropDownList(['...'],['multiple' => 'true'])
...

controller
...
if ($model->load(Yii::$app->request->post()) && $model->save()) {
    return $this->redirect(['...']);
}
...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Donkovtsev, 2016-05-24
@DmitriyFrolov

Find the method in the model
And add your variable to it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question