重写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();

上一篇:pytest框架-介绍、Mark(打标签)、命令运行用例、用例执行顺序、


下一篇:Python Number(数字)