9. How to obtain the administrator currently logged in or logged-in user information in the controller or model

In the base class FastAdmin provided Frontend, Backend, Apiin both provide access to the current administrator or user login information method

In the back office of the controller can $this->auth->idbe obtained administrator ID, $this->auth->字段名for additional information administrator, if needs to obtain the administrator ID currently logged in the background Model can be acquired in two ways:

First, use the Session to Obtain Administrator Information

\think\Session::get('admin');

Second, to obtain using a single Example

$auth = \app\admin\library\Auth::instance();

The controller or the front desk of the API can be $this->auth->idused to get the currently logged membership ID, $this->auth->字段员for additional information logon members, if the user needs to obtain information about the currently logged in at the front desk Model, and may be able to get the following ways:

//获取Auth对象
$auth = \app\common\library\Auth::install();
//获取会员模型
$user = $auth->getUser();

 

Guess you like

Origin www.cnblogs.com/apolloren/p/12155162.html