一、Code样例

  1. <?php
  2. namespace App\Module\Cms\Controller;
  3. use Swork\Server\Http\Argument;
  4. use ......
  5. /**
  6. * 资讯内容控制器
  7. * @Controller("/cms/info")
  8. */
  9. class InfoController extends BeanCollector
  10. {
  11. /**
  12. * @Inject()
  13. * @var InfoLogic
  14. */
  15. private $infoLogic;
  16. /**
  17. * 根据分类ID获取资讯内容的列表数据
  18. * @param Argument $argument
  19. * @return array
  20. * @throws
  21. */
  22. public function list(Argument $argument)
  23. {
  24. //外部参数
  25. $cid = $argument->get('cid', 0);
  26. //获取数据
  27. $list = $this->infoLogic->getList($cid);
  28. //返回
  29. return $list;
  30. }
  31. }

二、解析说明

1)类名注释为XX业务块的控制器
2)方法名pager注释为获取XX业务块的列表数据
3)三段式注释:外部参数、获取数据、返回;
不能直接在获取数据时返回,如:return $this->infoLogic->getList($cid); (无外部参数除外)
4)返回结果的参数固定为$list 。

三、无查询字段样例

  1. <?php
  2. public function list(Argument $argument)
  3. {
  4. return $this->infoLogic->getList();
  5. }

四、需要补充数据样例

  1. <?php
  2. public function list(Argument $argument)
  3. {
  4. //外部参数
  5. $cid = $argument->get('cid', 0);
  6. //获取数据
  7. $list = $this->infoLogic->getList($cid);
  8. //如有数据
  9. if(count($list) > 0)
  10. {
  11. //提取数据
  12. .....
  13. //补充数据
  14. foreach($list as $key => $item)
  15. {
  16. $list[$key]['sname'] = xxxx;
  17. }
  18. }
  19. //返回
  20. return $list;
  21. }