一、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;
/**
* 根据分类ID获取资讯内容的列表数据
* @param Argument $argument
* @return array
* @throws
*/
public function list(Argument $argument)
{
//外部参数
$cid = $argument->get('cid', 0);
//获取数据
$list = $this->infoLogic->getList($cid);
//返回
return $list;
}
}
二、解析说明
1)类名注释为XX业务块的控制器
2)方法名pager注释为获取XX业务块的列表数据
3)三段式注释:外部参数、获取数据、返回;
不能直接在获取数据时返回,如:return $this->infoLogic->getList($cid); (无外部参数除外)
4)返回结果的参数固定为$list 。
三、无查询字段样例
<?php
public function list(Argument $argument)
{
return $this->infoLogic->getList();
}
四、需要补充数据样例
<?php
public function list(Argument $argument)
{
//外部参数
$cid = $argument->get('cid', 0);
//获取数据
$list = $this->infoLogic->getList($cid);
//如有数据
if(count($list) > 0)
{
//提取数据
.....
//补充数据
foreach($list as $key => $item)
{
$list[$key]['sname'] = xxxx;
}
}
//返回
return $list;
}