zoukankan      html  css  js  c++  java
  • YII2 Gridview

    YII2 Gridview 部分使用规则

    1.页面显示的时间戳转换
    a.

    [
            'label'=>'创建日期',
            'attribute' => 'created_at',
            'filter' => false, //不显示搜索框
            'value' => function($data) {
                   return date('Y-m-d H:i:s',$data->created_at); }
    ],
    

    b.

    [
            'label'=>'创建日期',
            'attribute' => 'created_at',
            'format' => ['date', 'php:Y-m-d H:i:s'],
    ],
    

    2.为字段加超链接

    [ 
          'attribute'=>'title’,
          'format'=>'raw’,
          'value'=> function($data){return Html::a($data->title,['exam/index', 
                'id' => $data->_id],['title' => '审核']);} 
    ],
    
    [
         'label'=>'更多操作’, 
         'format'=>'raw’,
         'value' => function($data) { 
               $url = "http://www.baidu.com”; 
               return Html::a('添加权限组', $url, ['title' => '审核']); } 
    ],
    

    3.下拉菜单搜索

    [
                'label' => '当前状态',
                'attribute' => 'status',
                'filter' => Html::dropDownList('AppBaseSearch[status
    ]',$searchModel-> status,
                        [ '' => '请选择',
                        ‘0' => '审核拒绝', 
                        ‘1' => '审核通过', 
    		]),
    
         'value' => function($date) {
                        switch ($date-> status) {
                            case 1';
                                return '审核通过';
                                break;
                            case ‘0';
                                return '审核拒绝';
                                break;
                            default:
                                return '未知状态';
                                break;
                        }
                    }
                ],
    

    4.私人定制增删改按钮

    [
                    'header' => "查看/审核",
                    'class' => 'yiigridActionColumn',
                    'template'=> '{view} {update} {delete}',
                    'headerOptions' => ['width' => '140'],
                    'buttons' => [
                        'view' => function ($url, $model, $key) {
                            return Html::a(Html::tag('span', '', ['class' => "glyphicon fa fa-eye"]), ['admin/view-app', 'id'=>$model->app_id], ['class' => "btn btn-xs btn-success", 'title' => '查看']);
                        },
                        'update' => function ($url, $model, $key) use($uid){
                              return Html::a('通过', ['admin/reviewapp','id'=>$model->app_id, 'status’=>1], ['class' => "btn btn-xs btn-info"]);
                        },
                        'delete' => function ($url, $model, $key) {
                                return Html::a('拒绝', ['admin/reviewapp', 'id' => $model->app_id, 'status’=>0], ['class' => "btn btn-xs btn-danger"]);
                        }
                    ]
    ],
    
  • 相关阅读:
    在Spring中使用cache(EhCache的对象缓存和页面缓存)
    halcon 模板匹配 -- 转化 vector_angle_to_rigid
    halcon 模板匹配 -- find_shape_model
    halcon 模板匹配 -- create_shape_model
    C#快速获取指定网页源码的几种方式,并通过字符串截取函数 或 正则 取指定内容(IP)
    C# Socket通讯 本机多网卡,指定网卡通讯
    C# 获取所有网卡信息
    C#关闭退出线程的几种方法
    C#多线程方法 可传参
    C# Datetime 使用详解
  • 原文地址:https://www.cnblogs.com/GaoAnLee/p/5197773.html
Copyright © 2011-2022 走看看