Good night all.

view

$form = ActiveForm::begin(); .... echo Html::checkbox('category[]', false, ['value' => $childs['id'], 'label'=> $childs['title']]) . '<br>'; .... $form = ActiveForm::end(); 

var_dump

 [ '_csrf' => 'ZTROVV8ta1IneQstDV4/ZhxWLDg0axoNVmI.Ni1sWQUQRQpmL14aPQ==' 'category' => [ 0 => '262' 1 => '264' 2 => '265' ] ] 

262, 264, 265 are id categories. Help how to save!

    1 answer 1

    1. If the maximum number of categories is known, then you can add as many fields to the table — a bad option, but you can quickly process it.
    2. To collect category IDs in an array and write them in a single field, separated by commas - so-so option, because it imposes limitations on potential opportunities.
    3. Creating an additional table, where to write the entities and the ideas of the category, is slightly more difficult to process, but it is possible to get some statistics on the number of categories for the entity (all entities with less than 2 categories, all entities with more than 5 categories, entities with no categories, popular categories, popular categories for a particular entity, etc.)

    The third option is more acceptable, because it is not known how events will develop further. Fields: id, entity_id, cat_id