Tuesday, May 1, 2018

yii2 bootstrap modal popup

For implementing this you need to call default modal of Yii2 and begin and end modal is must

In step 2 you need to add javascipt for call the modal on button click.

In step 3 you need to create a action which render the data into your view.

How to add bootstrap modal in yii2

Add in your view:
//php code
Modal::begin([
    'header' => 'your header',
    'id'=>'modal',
     size'=>'modal-lg',
]);

echo '';

Modal::end();

Html::button('Button Name', ['value' => Url::to(['url/to']), 'title' => 'Title', 'class' => 'showModalButton btn btn-success']);

//javascript code
$('button').click(function(){
$('#modal').modal('show')
.find('#modalContent')
.load($(this).attr('value'));
})

Add in your controller/action:
//php code
if(Yii::$app->request->isAjax){
        return $this->renderAjax('your-view-file', [
            'data' => $data,
        ]);

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete

  2. It is nice post and I found some interesting information on this blog, keep it up. Thanks for sharing. . .
    Remote Yii Framework Team

    ReplyDelete
  3. Good day. I was impressed with your article. Keep it up . You can also visit my site if you have time. Thank you and Bless you always.
    Remote Yii Framework Development in India

    ReplyDelete

Recent Update

yii2 session handling

use yii\web\Session; $session = Yii::$app->session; // start session $session->open(); // close session $session->close(); ...

Most Search