How to pass multiple values which is entered in the checkboxes in Yii 2?

Good day! There are a few checkboxes when I submit the form it is entered in the database only the value of the first button. The rest is lost...
public function actionAddHouse(){
 $model = new House();
 $realtors = Realtors::find()->asArray()->all();
if($model->load(Yii::$app->request->post())){
if($model->save()){
 Yii::$app->session->setFlash('success', 'the House has put on sale!');
 return $this->refresh();
 } else {
 Yii::$app->session->setFlash('error', 'Error filling in the form!');
}
}
 return $this->render('house', compact('model', 'realtors'));
 }

And here is how to implement own boxes:
<?php $items = \yii\helpers\ArrayHelper::map($realtors, 'id', 'name') ?>
<?=$form--->field($model, 'realtor_id')->checkboxList($items) ?>
July 4th 19 at 23:27
1 answer
July 4th 19 at 23:29
Solution
radio buttons

why then checkboxList?
If radio is all right, they should give 1 selection if all checkbox - see that post request is emitted. And in the end You save. With the checkboxes is not a standard crud so as to fly needs an array, which then seems necessary or json to drive or to go through and save where necessary.
Your action and don't have anything to save if not overridden in the model beforeSave. If overridden, then the code in the Studio.
Edited the question) Made a typo) - Lindsay.Goldne commented on July 4th 19 at 23:32
How to do that would have left it an array? And about the beforeSave I learn more. Just new to Yii2 is still not know everything) - Lindsay.Goldne commented on July 4th 19 at 23:35
: still the mind "radio buttons" and checkboxList so in reality? - Henderson_Beat commented on July 4th 19 at 23:38
Oh, not all edited))) There is a checkboxList. - Lindsay.Goldne commented on July 4th 19 at 23:41
: "How to do that would have left it an array?" and so he flies away. The question is, what are You trying to save it as an array in a single cell. Must either have a linked table and to enter, going through the array or before it is stored in berofeSave to do
yii\helpers\Json::encode($this->realtor_id);
and in afterFind
yii\helpers\Json::decode($this->realtor_id); - Henderson_Beat commented on July 4th 19 at 23:44
Yeah! Thank you very much! And without json? It is possible to see in what form it transmits to the processing array with realtors? What would it do to the string? Or drain I'll do with this array? - Lindsay.Goldne commented on July 4th 19 at 23:47
: Can, enable debag panel, without it actually hellishly difficult to catch bugs and development lead.
www.yiiframework.com/doc-2.0/yii-debug-module.html - Henderson_Beat commented on July 4th 19 at 23:50
And do not tell me where and how to enable it?) As far as I understand this is the inheritance of ActiveRecord? - Lindsay.Goldne commented on July 4th 19 at 23:53
no. the debug panel is connected in the config, like so:
'bootstrap' => ['log','debug','gii'],
 'modules' => [
 'debug' => [
 'class' => 'yii\debug\Module',
 'allowedIPs' => ['111.111.111.111'] //here your ip
],
]
- Henderson_Beat commented on July 4th 19 at 23:56
Thank you very much! You are very helpful) - Lindsay.Goldne commented on July 4th 19 at 23:59

Find more questions by tags PHPProgrammingYii