Reputation: 177
I'm trying to add a modal to my navbar.
This is my \views\project_form.php:
<?php Modal::begin(['id' => 'modal', ?>
<?= $form->field($model, 'Wert')->textInput(['maxlength' => true]) ?>
<?php Modal::end(); ?>
and this is my Controller:
function actionShowmodal(){
$js='$("#modal").modal("show")';
$this->getView()->registerJs($js);
return $this->render('create');
}
I did this as it was described here how can I add modal to navbar in yii2 using yii2 -bootstrap extension?.
When I use a modal navbar in my index.php it works. But when I use a modal navbar in my form, an error is issued: Undefined variable: model.
How can I fix it?
Upvotes: 0
Views: 119
Reputation: 1020
In order to create a form in modal you need to pass the respective model for the form
function actionShowmodal(){
$model = new RespectiveModel(); //Model For the Form
$js='$("#modal").modal("show")';
$this->getView()->registerJs($js);
return $this->render('create',["model"=>$model]);
}
and in your "create.php" view file where you are rendering the form, pass the model variable again
echo $this->render('project_form',["model"=>$model]);
Upvotes: 1