I display list of rows from table on update page, and I want to update each row one by one using Bootstrap modal. I’ve gone through this article but it didn’t work - http://www.yiiframework.com/wiki/806/render-form-in-popup-via-ajax-create-and-update-with-ajax-validation-also-load-any-page-via-ajax-yii-2-0-2-3/
Here is my current code:
Update View Code:
<?php
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use yii\bootstrap\Modal;
?>
<?php $form = ActiveForm::begin(); ?>
<table class="table">
<thead>
<tr>
<th>Type</th>
<th>Size</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach($config as $index=>$value): ?>
<tr>
<td><?= $value->type ?></td>
<td><?= $value->size ?></td>
<td>
<?= Html::button('Edit', ['value' => Url::to(['site/update', 'id' => $value->id]), 'title' => 'Update Config', 'class' => 'btn btn-default update-btn']); ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php ActiveForm::end(); ?>
Update Controller:
public function actionUpdate()
{
$config = ProjectConfig::find()->where(['project_id' => 19])->all();
return $this->render('update', [
'config' => $config
]);
}
And here is modal code:
<?php
yii\bootstrap\Modal::begin([
'headerOptions' => ['id' => 'modalHeader'],
'id' => 'myModal',
'size' => 'modal-lg',
//keeps from closing modal with esc key or by clicking out of the modal.
// user must click cancel or X to close
'clientOptions' => ['backdrop' => 'static', 'keyboard' => FALSE]
]);
echo Yii::$app->controller->renderPartial('_form');
yii\bootstrap\Modal::end();
?>
How can I make the _form dynamic passing the model from controller.