最新消息: 新版网站上线了!!!

yii2 弹出层配置

yii2 弹出层
Modal::begin();
    echo $this->render('edit_post_form', ['model' => Post::findOne(my_post_id)]);
Modal::end();
 
<?= \yii\bootstrap\Modal::widget([
    'id' => 'contact-modal',
    'toggleButton' => [
        'label' => 'Обратная связь',
        'tag' => 'a',
        'data-target' => '#contact-modal',
        'href' => Url::toRoute(['/main/contact']),
    ],
    'clientOptions' => false,
]); ?>
 
$model = new ContactForm();
return $this->renderAjax('contact', [
  'model' => $model,
]);
 
$js = <<<JS
jQuery('#contact-form').on('beforeSubmit', function(){
    var form = jQuery(this);
    jQuery.post(
        form.attr("action"),
        form.serialize()
    )
    .done(function(result) {
        form.parent().replaceWith(result);
    })
    .fail(function() {
        console.log("server error");
    });
    return false;
})
JS;
$this->registerJs($js);

转载请注明:谷谷点程序 » yii2 弹出层配置