php – 将参数传递给分形变换器变换方法

前端之家收集整理的这篇文章主要介绍了php – 将参数传递给分形变换器变换方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用PHPleague的分形包.我有这样的变换类设置
class ConversationTransformer extends TransformerAbstract
    {

        public function transform (Conversation $conversation,$user)
        {
            return [];
        }
    }

但是,当我尝试访问它时,我得到了转换的参数2异常

$user = $this->people->get($this->user());
//conversations
$conversations = $this->conversations->user($user);
return $this->fractal->paginatedCollection($conversations,$user,new ConversationTransformer());
class ConversationTransformer extends TransformerAbstract
{
    private $params = [];

    function __construct($params = [])
    {
        $this->params = $params;
    }

    public function transform (Conversation $conversation)
    {
        //-- $this->params will be used here            

        return [];
    }
}

用这个回报来称呼它:

return $this->fractal->paginatedCollection($conversations,new ConversationTransformer(['user' => $user]))

猜你在找的PHP相关文章