一、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 info(Argument $argument)
  23. {
  24. //外部参数
  25. $fid = $argument->get('fid', 0);
  26. //获取数据
  27. $info = $this->infoLogic->getInfo($fid);
  28. //返回
  29. return $info;
  30. }
  31. /**
  32. * 根据信息ID获取资讯详细内容(提供给表单编辑使用)
  33. * @param Argument $argument
  34. * @return array
  35. * @throws
  36. */
  37. public function detial(Argument $argument)
  38. {
  39. //外部参数
  40. $fid = $argument->get('fid', 0);
  41. //获取数据
  42. $info = $this->infoLogic->getDetail($fid);
  43. //返回
  44. return $info;
  45. }
  46. }

二、解析说明

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

三、info和detail区别

方法名 描述说明
info 当返回数据:
既提供给页面(UI)展示用,
又要提供给编辑表单绑定原始值使用
detail 仅提供给编辑表单绑定原始值使用

四、无外部参数样例

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

五、需要补充数据样例

  1. <?php
  2. public function info(Argument $argument)
  3. {
  4. //外部参数
  5. $cid = $argument->get('cid', 0);
  6. //获取数据
  7. $info = $this->infoLogic->getInfo($cid);
  8. //如有数据
  9. if($info != false)
  10. {
  11. $info['sname'] = xxxx;
  12. }
  13. //返回
  14. return $info;
  15. }