I search for a solution for clicking on a link in an ActionColumn - Action to open a Modal.
thats not working
return Html::a('<span class="glyphicon glyphicon-earphone"></span>',
Url::toRoute(['controlloer/createlink','id' => '1']),
[ 'id' => 'modalCall',
]);
For buttons there is a good Dokumentation for handling it.
My Solution helps maybe other, or better solution will come up:
View.php
return Html::a('<span class="glyphicon glyphicon-earphone"></span>',
"javascript:void(0)",
[
'id' => 'myModal',
'value'=>Url::toRoute(['call/createlink','id' => '1'])// modalCall
]);
<?php
Modal::begin([
'header' => '<h4></h4>',
'id' => 'modal',
'size' => 'modal-lg',
]);
echo "<div id='modalContent'>Modal</div>";
Modal::end();
?>
main.js
$(function(){
$('#myModal').click(function(){
$('#modal').modal('show')
.find('#modalContent')
.load($(this).attr('value'))
});
});
controller.php
public function actionCreatelink($id)
{
$model = new Call();
$model->cid = $id;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(Yii::$app->request->referrer);
} else {
return $this->renderAjax('create', [
'model' => $model,
]);
}
}