Show more than one modal on the same page


How can I show more than one(overlay) modal on the same page?

I now I must change the id of the modal, but how to do that from the view.

I use this code to show the modal.

in main.php (layout)

<?php yii\bootstrap\Modal::begin([

        'options' => [

            'id' => 'modalDialog',


        'size' => 'modal-lg',

        'header' => '<h4 id="modalTitle">Edit...</h4>',

        'footer' =>

            Html::button('Close', ['class' => 'btn btn-default', 'data-dismiss' => 'modal'])

            . PHP_EOL .

            Html::button('Save', ['class' => 'btn btn-primary btn-modal-save', 'id' => 'saveModel'])

            . PHP_EOL .

            Html::button('Delete', ['class' => 'btn btn-danger btn-modal-delete', 'id' => 'deleteModel']),

        ]); ?>


    <div id='modalContent'></div>


    <?php yii\bootstrap\Modal::end() ?>

And to show the modal.

In the view

 <?= Html::a('Create Project', false, [ 'class' => 'createModel btn btn-success' ]) ?>


$script = <<< JS

$(document).on('click', '.createModel', function(e){




        url: '/project/edit',

        type: 'POST',

        success: function(data) {





            document.getElementById('modalTitle').innerHTML = '<h4>' + 'Create project' + '</h4>';            






The code I use to show the modal is this:










is where it show the modal to the user. Just change the #modal to the modal Id you need to show.

Thx Contreras,

This code works for showing one model to be open, but the second one the page will overwrite the first one.

I want to open more than one modal window on the same page (as overlay).

Can’t you just copy the JS to have 2 or more modals?