一、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 info(Argument $argument)
{
//外部参数
$fid = $argument->get('fid', 0);
//获取数据
$info = $this->infoLogic->getInfo($fid);
//返回
return $info;
}
/**
* 根据信息ID获取资讯详细内容(提供给表单编辑使用)
* @param Argument $argument
* @return array
* @throws
*/
public function detial(Argument $argument)
{
//外部参数
$fid = $argument->get('fid', 0);
//获取数据
$info = $this->infoLogic->getDetail($fid);
//返回
return $info;
}
}
二、解析说明
1)类名注释为XX业务块的控制器
2)方法名pager注释为获取XX业务块的列表数据
3)三段式注释:外部参数、获取数据、返回;
不能直接在获取数据时返回,如:return $this->infoLogic->getInfo($cid); (无外部参数除外)
4)返回结果的参数固定为$info 。
三、info和detail区别
方法名 | 描述说明 |
---|---|
info | 当返回数据: 既提供给页面(UI)展示用, 又要提供给编辑表单绑定原始值使用 |
detail | 仅提供给编辑表单绑定原始值使用 |
四、无外部参数样例
<?php
public function info(Argument $argument)
{
return $this->infoLogic->getInfo();
}
五、需要补充数据样例
<?php
public function info(Argument $argument)
{
//外部参数
$cid = $argument->get('cid', 0);
//获取数据
$info = $this->infoLogic->getInfo($cid);
//如有数据
if($info != false)
{
$info['sname'] = xxxx;
}
//返回
return $info;
}