2018-02-28 10:58:09 2171次浏览 1条回答 0 悬赏 20 金钱

比如:backend/view/post/index.php代码:

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
       // ['class' => 'yii\grid\SerialColumn'],

        //'id',
        ['attribute'=>'id',
        'contentOptions'=>['width'=>'30px'],
        ],
        'title',
        //'author_id',
        ['attribute'=>'authorName',
        'label'=>'作者',
        'value'=>'author.nickname',
        ],
       // 'content:ntext',
        'tags:ntext',
        //'status',
        ['attribute'=>'status',
        'value'=>'status0.name',
        'filter'=>Poststatus::find()
                ->select(['name','id'])
                ->orderBy('position')
                ->indexBy('id')
                ->column(),
         ],
        // 'create_time:datetime',
         //'update_time:datetime',
         ['attribute'=>'update_time',
         'format'=>['date','php:Y-m-d H:i:s'],
        ],


        ['class' => 'yii\grid\ActionColumn'],
    ],
]); ?>

其中的status0.name是什么含义?

最佳答案

  • 菜鸟鼻涕 发布于 2018-02-28 14:11 举报

    status0.name 是 post模型关联到state模型里的name字段,你看下post模型里有个方法是不是叫state0()?这个是关联到state模型的数据,而在gridview调用可以用state0.xxx(xxx表示字段)。为什么方法state0()调用name 可以写成 state0.name 你可以参考下源码

    1 条回复
    回复于 2018-03-01 09:06 回复

    手误了,state0()改成getstate0()

    , 觉得很赞
    没有找到数据。
您需要登录后才可以回答。登录 | 立即注册
Sanlence
助理

Sanlence

注册时间:2017-04-10
最后登录:2021-07-24
在线时长:5小时48分
  • 粉丝0
  • 金钱115
  • 威望0
  • 积分165

热门问题