一、Code样例
<?php
namespace App\Module\Cms\Controller;
use Swork\Server\Http\Argument;
use ......
/**
* 资讯内容控制器
* @Controller("/cms/info")
*/
class InfoController extends BeanCollector
{
/**
* @Inject()
* @var InfoLogic
*/
private $infoLogic;
/**
* 获取资讯内容的翻页列表
* @param Argument $argument
* @return array
* @throws
*/
public function pager(Argument $argument)
{
//外部参数
$idx = $argument->get('idx', 1);
$size = $argument->get('size', 25);
//查询字段
$query = [
'cid' => $argument->get('cid', 0),
'title' => $argument->get('title', ''),
];
//获取数据
$list = $this->infoLogic->getPager($query, $idx, $size);
//返回
return $list;
}
}
二、解析说明
1)类名注释为XX业务块的控制器
2)方法名pager注释为获取XX业务块的翻页数据
3)四段式注释:外部参数、查询字段(如无额外字段时可去掉)、获取数据、返回;
不能直接在获取数据时返回,如:return $this->infoLogic->getPager($query, $idx, $size);
4)getPager标准要求使用三个参数传入,并固定为 $query, $idx, $size。
5)过滤条件的字段统一由$query组装参数传入。
6)返回结果的参数固定为$list 。
三、无查询字段样例
<?php
public function pager(Argument $argument)
{
//外部参数
$idx = $argument->get('idx', 1);
$size = $argument->get('size', 25);
//获取数据
$list = $this->infoLogic->getPager($idx, $size);
//返回
return $list;
}
四、需要补充数据样例
<?php
public function pager(Argument $argument)
{
//外部参数
$idx = $argument->get('idx', 1);
$size = $argument->get('size', 25);
//获取数据
$list = $this->infoLogic->getPager($idx, $size);
//如有数据
if(count($list) > 0)
{
//提取数据
.....
//补充数据
foreach($list as $key => $item)
{
$list[$key]['sname'] = xxxx;
}
}
//返回
return $list;
}