一、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. * 获取资讯内容的翻页列表
  18. * @param Argument $argument
  19. * @return array
  20. * @throws
  21. */
  22. public function pager(Argument $argument)
  23. {
  24. //外部参数
  25. $idx = $argument->get('idx', 1);
  26. $size = $argument->get('size', 25);
  27. //查询字段
  28. $query = [
  29. 'cid' => $argument->get('cid', 0),
  30. 'title' => $argument->get('title', ''),
  31. ];
  32. //获取数据
  33. $list = $this->infoLogic->getPager($query, $idx, $size);
  34. //返回
  35. return $list;
  36. }
  37. }

二、解析说明

1)类名注释为XX业务块的控制器
2)方法名pager注释为获取XX业务块的翻页数据
3)四段式注释:外部参数、查询字段(如无额外字段时可去掉)、获取数据、返回;
不能直接在获取数据时返回,如:return $this->infoLogic->getPager($query, $idx, $size);
4)getPager标准要求使用三个参数传入,并固定为 $query, $idx, $size。
5)过滤条件的字段统一由$query组装参数传入。
6)返回结果的参数固定为$list 。

三、无查询字段样例

  1. <?php
  2. public function pager(Argument $argument)
  3. {
  4. //外部参数
  5. $idx = $argument->get('idx', 1);
  6. $size = $argument->get('size', 25);
  7. //获取数据
  8. $list = $this->infoLogic->getPager($idx, $size);
  9. //返回
  10. return $list;
  11. }

四、需要补充数据样例

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