In tp5 can request to the Request object binding properties to facilitate the global call . For example, we can bind the currently logged in user model common controller to the request object.
1. First Binding in public controllers:
<?php
namespace app\common\controller;
use app\index\model\User;
use think\Controller;
use think\Request;
use think\Session;
class Base extends Controller
{
public function _initialize(){
$user = User::get(Session::get("user_id"));
Request::instance()->bind("user",$user);
//$this->request->bind("user",$user);
}
}
2. Obtain the property (controller):
Request::instance()->user;
//$this->request->user;
//request()->user;