【TP5 :请求】方法注入

版权声明:本文为ywcmoon原创文章,未经允许不得转载。 https://blog.csdn.net/qq_39251267/article/details/82626928

方法注入

使用Request对象的hook方法的注入功能,在Request请求对象中添加自定义方法

// 通过hook方法注入动态方法
Request::hook('user','getUserInfo');

getUserInfo函数定义如下

function getUserInfo(Request $request, $userId)
{
    // 根据$userId获取用户信息
    return $info;
}

在控制器中调用

public function index()
{
    $info = Request::instance()->user($userId);
}

猜你喜欢

转载自blog.csdn.net/qq_39251267/article/details/82626928