我正在使用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());@H_403_7@
@H_403_7@
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]))@H_403_7@ 原文链接:https://www.f2er.com/php/135106.html