// This section can be moved to "\views\layouts\main.php"
yii\bootstrap\Modal::begin([
'header' => '<span id="myModalTitle">Title</span>',
'id' => 'myModalDialog1',
'size' => 'modal-lg',
]);
echo "<div id='myModalContent'></div>";
yii\bootstrap\Modal::end();
$this->registerJs(
"// If you use $(document).on, it will handle also events on elements rendered by AJAX.
// $(document).on('click','a.openInMyModal',function(e){
// And if you use $('a.openInMyModal'), it will work only on standard elements
// $('a.openInMyModal').click(function(e){
// Prevents the browsers default behaviour (such as opening a link)
[...]
// Good idea is to set onclick='return false;' to the link if it is in a modal window
let title = $(this).attr('data-myModal-tTitle');
if (title==undefined) { title = ''; }
$('#myModalDialog1 #myModalTitle').text(title);
$('#myModalDialog1').modal('show')
.find('#myModalContent')
.load($(this).attr('href'));
return false;
});",
yii\web\View::POS_READY,
'myModalHandler'
);
?>