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

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

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

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
最佳答案
  • 官方文档有定义:

    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.
  • 可以看到写法有不同,原因我分析了一下,在此
6年前 评论
讨论数量: 3
liyu001989

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

6年前 评论

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

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

    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.
  • 可以看到写法有不同,原因我分析了一下,在此
6年前 评论

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