如何在 yii2 中将默认登录页面显示为模态弹出窗口? [英] How can i show the default login page as modal popup in yii2?

查看:48
本文介绍了如何在 yii2 中将默认登录页面显示为模态弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何在 yii2 中将默认登录页面提升为模型弹出窗口?

谢谢

解决方案

登录链接

Login<div class="modalfade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div><脚本>函数登录(){$.ajax({类型:'POST',url:'index.php?r=site/login',成功:功能(数据){$('#myModal').html(data);$('#myModal').modal();}});}

在控制器中(站点控制器/登录操作)

return $this->renderAjax('_login', ['模型' =>$模型,]);

您必须创建一个部分文件

部分查看_login.php

<!-- 显示弹出登录的模态对话框--><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" ><span aria-hidden="true">&次;</span><span class="sr-only">关闭</span></button><h4 class="modal-title" id="myModalLabel">登录</h4>

<div class="modal-body"><!-- 启动 ActiveForm --><?php $form = ActiveForm::begin(['id' => 'login-form','enableClientValidation'=>'true']);?><?= $form->field($model, '用户名',['模板' =>"{标签}\n{错误}\n{输入}\n{提示}\n",'errorOptions'=>['class'=>'help-block alert alert-danger','style'=>'display:none;']]) ?><?= Html::a('忘记密码?', ['site/repassword'],['class'=>'password-recovery']) ?><?= $form->field($model, '密码',['模板' =>"{标签}\n{错误}\n{输入}\n{提示}\n",'errorOptions'=>['class'=>'help-block alert alert-danger','style'=>'display:none;']])->passwordInput() ?><div class="modal-footer"><div class="form-group our-form-group"><?= Html::a('注册', ['网站/注册']) ?><?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>

<?php ActiveForm::end();?>

Can anybody please tell me how can i raise the default login page as model popup in yii2?

Thanks

解决方案

Login link

<a href="javascript:void(0);" onclick="login();return false;">Login</a>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
<script>
   function login(){
      $.ajax({
          type:'POST',
          url:'index.php?r=site/login',
          success: function(data)
                   {
                       $('#myModal').html(data);
                       $('#myModal').modal();
                   }
      });
   }
</script>

In Controller (Site controller/login action)

return $this->renderAjax('_login', [
    'model' => $model,
]);

You have to create a partial file

Partial view _login.php

<?php 
    use yii\helpers\Html;
    use yii\widgets\ActiveForm;
?>
<!-- modal dialog for display pop up login -->
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" ><span aria-hidden="true">&    times;</span><span class="sr-only">Close</span></button>
    <h4 class="modal-title" id="myModalLabel">Login</h4>
</div>
<div class="modal-body">
    <!-- start ActiveForm -->
    <?php $form = ActiveForm::begin(['id' => 'login-form','enableClientValidation'=>'true']); ?>

    <?= $form->field($model, 'username',[
                                  'template' => "{label}\n{error}\n{input}\n{hint}\n",
                                  'errorOptions'=>['class'=>'help-block alert alert-danger','style'=>'display:none;']
                             ]
                    ) ?>
    <?= Html::a('Forgot your password?', ['site/repassword'],['class'=>'password-recovery']) ?>
    <?= $form->field($model, 'password',[
                   'template' => "{label}\n{error}\n{input}\n{hint}\n",
                   'errorOptions'=>['class'=>'help-block alert alert-danger','style'=>'display:none;']
                ])->passwordInput() ?>
   <div class="modal-footer">
   <div class="form-group our-form-group">
         <?= Html::a('Sign up', ['site/signup']) ?>
         <?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
   </div>
   <?php ActiveForm::end(); ?>
</div>
</div>
</div>

这篇关于如何在 yii2 中将默认登录页面显示为模态弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆