重写Fields 控制models 数据输出字段

 

models:

public function Fields()
{
  $fields = parent::Fields();//原来models输出字段

    $fields['parentComment'] = function (self $model){//‘parentComment’自定义输出字段

  return ShopComment::find()->select('content')->where(['parent_id'=>$model->comment_id])->One();//列子是 查找评论父级数据;
};

return $fields;
}

 

controller:

$models = shopComment::find()->where(['comment_id'=>6])->One();
$models = $models->toArray();

posted @ 2017-10-27 17:41  百事可口  阅读(115)  评论(0编辑  收藏  举报