Thank you very much for your reply!
I think I’m very close to the solution…
Thanks to your advice I can see the form with all the categories I want, but if I check one or more category, it save correctly the question into table but not the ID into the relation table.
I checked the post array via
print_r(Yii::$app->request->post());
and I see the IDs I checked but when I do
$model->save()
it saves only the field of Question class… Sure I miss something, but I cannot see where…
This is the code of my Question Controller for create action:
public function actionCreate()
{
$model = new Domande;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->ID]);
} else {
return $this->render('create', [
'model' => $model,
'categorie' => Categories::getAllCategories(),
]);
}
}
This is my _form.php
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'qCategories')->checkBoxList(ArrayHelper::map($categories, 'ID', 'titolo')) ?>
<?= $form->field($model, 'domanda')->textarea(['rows' => 3]) ?>
<?= $form->field($model, 'commento')->textarea(['rows' => 3]) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
When I create the question, I have no errors, but there are no record in the link table between question and categories…
Thanks again for your help!