0

I have 2 tables items and categories. In the items form I need to list all categories so user check more than one category. So far I am listing categories like this:

foreach($items as $item) {
            $modelCategory->itemCategoryId = $item->id;
            echo $form->field($modelCategory, 'itemCategoryId')
             ->checkbox([
                        'value' => $item->id, 
                        'label' => ''])
             ->label($item->name);
}

But first problem is the name of the field, how can I convert it into array?

I am thinking in adding a virtual attribute to my Item called "categories", and then use checkBoxList, any other way?

1 Answer 1

1

I have solved with checkboxList!!

$items = $this->_getList();
$selectedItems = $this->_getSelected();

echo  $form->field($this->modelForm, 'itemCategories')->checkboxList($items, $selectedItems);

Thanks!!!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.