How to get Yox2.0 CheckboxList items, verified how the form loads?

I am trying to use the checkboxlist Activeform widget in the YII 2.0 Framework

in my case, I have an array called a β€œlist” that has the names of the languages ​​that will appear as checkboxlist, now I can do it, but I want the checkboxes to be checked as downloadable forms.

$list = [0 => 'PHP', 1 => 'MySQL', 2 => 'Javascript']; $list2 = [0,2]; 

using the following line, I can get what I want using HTML helper classes:

 <?= Html::checkboxList('CuisineId',$list2,$list); ?> 

but I want this to be possible with the CheckboxList Activeform Widget, which according to the documentation should be used as follows:

static checkboxList ($ items, $ options = [])

So, in my case, I figured out how to pass a parameter to $ items, which looks like this:

 <?= $form->field($record, 'CuisineId')->checkboxlist($list);?> 

But now I don’t know how to pass parameters that will check the checkboxes.

+8
php yii2
source share
2 answers

Ok, I got a solution from the yiiframework forum itself .

The solution was only to add the next line of code, and it worked!

 $record->CuisineId = $list2; 
+4
source share

Solve
database

view

controller

 $model = $this->findModel($id); $model->INDEXES =ArrayHelper::getColumn($model->publicationIndexes, 'INDEXES_ID'); if ($model->load(Yii::$app->request->post())) {$model->save();} 

View (_form)

 <?= $form->field($model, 'INDEXES')->checkboxList(ArrayHelper::map(Indexes::find()->all(), 'ID', 'NAME')) ?> 
+3
source share

All Articles