$this->response->item ($topic, new TopicTransformer ()),请问怎么理解 item 中的第一个参数呢?

return $this->response->item($topic, new TopicTransformer());

不知道理解的对不对,TopicTransformer() 返回的是return中内容,而 item($topic, new TopicTransformer()); 中的 $topic,是指指定$topic->id的内容。

《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
最佳答案
  • 官方文档有定义:

    Two types of resource exist:
    
    League\Fractal\Resource\Item - A singular resource, probably one entry in a data store
    League\Fractal\Resource\Collection - A collection of resources
    The Item and Collection constructors will take any kind of data you wish to send it as the first argument, and then a “transformer” as the second argument.
  • 可以看到写法有不同,原因我分析了一下,在此
7年前 评论
讨论数量: 3
liyu001989

怎么理解。。就是用 Transformer 格式化 Model 模型。我没看懂你的表述,你可以再描述一下你哪没懂

7年前 评论

@liyu001989 谢谢,看了后面的教程就懂了。

7年前 评论
  • 官方文档有定义:

    Two types of resource exist:
    
    League\Fractal\Resource\Item - A singular resource, probably one entry in a data store
    League\Fractal\Resource\Collection - A collection of resources
    The Item and Collection constructors will take any kind of data you wish to send it as the first argument, and then a “transformer” as the second argument.
  • 可以看到写法有不同,原因我分析了一下,在此
7年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!