獲取指定的列,並且設置某些列的別名:
swoole 4.5,easy_swoole 3.x
public function getUserInfo($id)
{
$user = UserModel::field(['id as user_id', 'nickname', 'avatar', 'country_code', 'telephone', 'email', 'language', 'xxx', 'xx'])
->get($id);
return $user;
}
注意:field方法一定要在get之前調用,不然查詢sql的時候還是會查出所有字段,然後再做的過濾。