• gridView在view页面中的一些代码详细模板


    <?php
    
    use yiihelpersHtml;
    use yiigridGridView;
    use yiiwidgetsPjax;
    use frontendmodelsItem;
    /* @var $this yiiwebView */
    /* @var $searchModel frontendmodelsItemSearch */
    /* @var $dataProvider yiidataActiveDataProvider */
    
    $this->title = 'Items';
    $this->params['breadcrumbs'][] = $this->title;
    ?>
    <div class="item-index">
    
        <h1><?= Html::encode($this->title) ?></h1>
        <?php Pjax::begin(); ?>
        <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
    
        <p>
            <?= Html::a('Create Item', ['create'], ['class' => 'btn btn-success']) ?>
        </p>
    
        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'columns' => [
                ['class' => 'yiigridSerialColumn'],
                [
                    'attribute' =>'cate_id',
                    'value' => function($model){
    
                        return Item::get_type_text($model->cate_id);
                    },
                    //'filter' =>是下拉列表过滤器
                    'filter' => Item::get_type(),
                ],
                'name',
                'buy_price',
                'sell_price',
                [
                    'attribute' => 'created_at',
                    'format'=>['date','php:Y-m-d H:m:s'],
                ],
                [
                    'attribute' => 'updated_at',
                    'format'=>['date','php:Y-m-d H:m:s'],
                ],
                [
                    'attribute' => 'status',
                    'value' => function($model){
                        return $model->status == 1?'在售':'停售';
                    },
                    'filter' => ['停售','在售'],
                ],
                // 'img_url:url',
    
                [
                'class' => 'yiigridActionColumn',
                ],
            ],
        ]); ?>
        <?php Pjax::end(); ?>
    </div>

    其中在model中的代码

        public static  function  get_type_text($id){
    
            $datas = Category::find()->all();
    
            $datas = ArrayHelper::map($datas, 'cate_id', 'cate_name');
    
            return  $datas[$id];
        }
    
        public static  function  get_type(){
    
            $cat = Category::find()->all();
    
            $cat = ArrayHelper::map($cat, 'cate_id', 'cate_name');
    
            return $cat;
        }

     在view页面,集合两个数据的column

    [
            'label'=>'省市',
            'attribute'=>'province',
            'value'=>function($data){
                return $data->province."-".$data->city;
            }
       ]
  • 相关阅读:
    记一次简单的正则表达式匹配实践
    使用readlines()读取文件时出现/n及其解决办法
    浅谈http和https
    JVM GC回收原理的认识
    Mysql中语言分类和区别
    关于storm程序性能压测记录及总结
    Java 集合框架
    MySQL binlog底层主从同步原理
    Docker-Compose安装
    gcc手动安装
  • 原文地址:https://www.cnblogs.com/jerrypro/p/6409817.html
Copyright © 2020-2023  润新知