zoukankan      html  css  js  c++  java
  • yii2GridView的简单使用

        GridView::widget([  
            'dataProvider' => $dataProvider,// 你传过来的ActiveDataProvider  
            // 'filterModel' => $searchModel,  
            'columns' => [  
                ['class' => 'yiigridSerialColumn'],// 第一列排序  
          
                'sid',// 第二列,sid,与你查询的model字段相对应,可以少,不可以多  
                [  
                    'attribute' => 'sname',  
                    'label'=>'姓名',// 自定义列名  
                ],// 第三列,sname  
          
                [  
                    'class' => 'yiigridActionColumn',// 动作列,默认三个动作,分别为{view},{update},{delete}  
                    'header' => '操作',// 列名  
                    'template' => '{stuent-view} {studnet-update} {student-delete}',// 定义这一列里面有几个操作,这里为查看,更新,删除  
                    'buttons' => [// 为你template中声明的操作声明动作  
                        'stuent-view' => function ($url, $models, $key) {// 对应{student-view},三个参数,最主要的$key,为你model主键的id  
                        $url = ['student/view', 'id'=>$key];// 为下面a链接的url,此处指向StudentController的actionView方法  
                            $options = [  
                                'title' => '查看',  
                                'aria-label' => '查看',  
                                'data-pjax' => '0',  
                            ];  
                            return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, $options);  
                        },  
                        'studnet-update' => function ($url, $models, $key) {// 对应{student-update}  
                            $url = ['student/update', 'id'=>$key];  
                            $options = [  
                                'title' => '更新',  
                                'aria-label' => '更新',  
                                'data-pjax' => '0',  
                            ];  
                            return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, $options);  
                        },  
                        'student-delete' => function ($url, $models, $key) {// 对应{student-delete}  
                            $url = ['student/delete', 'id'=>$key];  
                            $options = [  
                                'title' => '删除',  
                                'aria-label' => '删除',  
                                'data-pjax' => '0',  
                            'data-method' => 'post'  
                            ];  
                            return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, $options);  
                        }  
                    ]  
                ],// 操作  
            ],  
        ]);  
    
  • 相关阅读:
    常用的DOCS命令
    [51NOD1126]求递推序列的第n项(矩阵快速幂)
    [HDOJ2830]Matrix Swapping II(胡搞)
    [每天一道A+B]签到检测程序
    [HIHO1260]String Problem I(trie树)
    [HIHO1300]展胜地的鲤鱼旗(栈,dp)
    [HIHO1299]打折机票(线段树)
    [51NOD1087]1 10 100 1000(规律,二分)
    [POJ2002]Squares(计算几何,二分)
    [HDOJ1015]Safecracker(DFS, 组合数学)
  • 原文地址:https://www.cnblogs.com/jerrypro/p/6392139.html
Copyright © 2011-2022 走看看