Closed SemiThin closed 3 years ago
namespace App\Model;
class UsersModel extends BaseModel { protected $autoTimeStamp = true; protected $tableName = 'users';
protected function getAvatarAttr($value) { return $value ? 'http://www.baidu.com/' . $value : ''; }
}
使用 get(); all(); 的时候是有效的 $user = UsersModel::create()->get(1); $user = $user->toArray(); print_r($user);
Array ( [id] => 1 [mobile] => S5YAxLGit7BvBrf0QNHdfw== [name] => 吊车尾的 [avatar] => http://www.baidu.com/custom/head_portrait/1.png [position_id] => 0 [industry_id] => 0 [im_account] => 2021031130224 [status] => 1 [create_time] => 1615445948 [update_time] => 1615445948 )
这是使用indexBy 获取时候时 avatar 字段并没有经过处理 $user = UsersModel::create()->indexBy('id'); print_r($user);
Array ( [1] => Array ( [id] => 1 [mobile] => S5YAxLGit7BvBrf0QNHdfw== [name] => 吊车尾的 [avatar] => custom/head_portrait/1.png [position_id] => 0 [industry_id] => 0 [im_account] => 2021031130224 [status] => 1 [create_time] => 1615445948 [update_time] => 1615445948 )
)
这个indexBy不走gettet.你关闭掉吧.群里应该是回答你了.
indexBy
gettet
namespace App\Model;
class UsersModel extends BaseModel { protected $autoTimeStamp = true; protected $tableName = 'users';
}
使用 get(); all(); 的时候是有效的 $user = UsersModel::create()->get(1); $user = $user->toArray(); print_r($user);
Array ( [id] => 1 [mobile] => S5YAxLGit7BvBrf0QNHdfw== [name] => 吊车尾的 [avatar] => http://www.baidu.com/custom/head_portrait/1.png [position_id] => 0 [industry_id] => 0 [im_account] => 2021031130224 [status] => 1 [create_time] => 1615445948 [update_time] => 1615445948 )
这是使用indexBy 获取时候时 avatar 字段并没有经过处理 $user = UsersModel::create()->indexBy('id'); print_r($user);
Array ( [1] => Array ( [id] => 1 [mobile] => S5YAxLGit7BvBrf0QNHdfw== [name] => 吊车尾的 [avatar] => custom/head_portrait/1.png [position_id] => 0 [industry_id] => 0 [im_account] => 2021031130224 [status] => 1 [create_time] => 1615445948 [update_time] => 1615445948 )
)