zoukankan      html  css  js  c++  java
  • [moka同学笔记]Yii2.0 modal的使用

    第一次使用,时候不明白什么原理,大概用了几次后,才模模糊糊搞清楚原来是怎么一回事,现在就把写过的代码,贴在下边。

    1.在视图文件中,

    第一步首先在index.php文件中

    做了一个a链接的按钮 调用了modal
    
            <a class="btn btn-default pull-right" data-remote="<?= Url::toRoute(['create', '_wicket' => 'yes']) ?>"
               data-toggle="modal" data-target="#myModal" role="button">添加地区</a>
    
    
    <!--这里是其他代码-->
    
    <!-- Modal部分 -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="progress" style="margin:0;"><div class="progress-bar progress-bar-info progress-bar-striped active" role="progressbar" 
    aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style=" 1%"></div></div> </div> </div> </div>

    第二步其次,在create.php文件中

    <?php
    /**
     * Created by PhpStorm.
     * User: moka同学
     * Date: 2016/10/20
     * Time: 10:54
     */
    
    use yiihelpersHtml;
    use yiiwidgetsActiveForm;
    
    Main::register($this);
    
    ?>
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">添加地区</h4>
    </div>
    <?php $form = ActiveForm::begin([
        'options' => [
            'class' => '',
            'enctype'=>'multipart/form-data',
            'method'=>'post',
            'fieldConfig'=>[
                'template' => "{label}
    <div class="col-lg-3">{input}</div>
    <div class="col-lg-8">{error}</div>",
            ]
        ]
    ]); ?>
    
    <div class="modal-body">
    
    <!--其他代码-->如表单输入框等
    
    
     </div>
        </div>
    </div>
    
    <div class="modal-footer" style="border-top:0px">
        <button type="button" class="btn btn-primary submit-ajax col-lg-offset-2" data-loading-text="加载中..." autocomplete="off">确认</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
    </div>
    
    <?php ActiveForm::end(); ?>

    2.在控制器中

    在create.php中

        public function actionCreate(){
            $model = City::findOne($id);
        

    //其他代码 return $this->render('create',[ 'model'=>$model ]); }

    注意:有时候要用到ajax传递modal中的数据,ajax会把值传递到index中去,所以需要在index控制器中去进行相应的处理。

    转载请注明出处。

    我生活的地方,我为何要生活。
  • 相关阅读:
    l1-013
    将博客搬至CSDN
    Educational Codeforces Round 25
    大组合数取余模板【Lucas定理】
    Exams(二分求左界+贪心)
    Cutting (暴力 + 滚动哈希判字符串匹配)
    Cubes(DFS+剪枝)
    Codeforces Round #409 (Div. 2)
    【复习挖坑】dp + 图
    n & n-1 和 n & -n
  • 原文地址:https://www.cnblogs.com/hsd1727728211/p/6054673.html
Copyright © 2011-2022 走看看