API返回值在输出之前,必须先植入状态码否则将抛出异常,状态码统一存放在/restful/数据格式下标名/code.php
文件中。
通过\x\Restful::状态码下标()
的方法,可以反射获取到下标名称,然后通过\x\Restful::code(传入)
方法植入进去。
以/restful/default/code.php
中的状态码为例,如果要读取里面的SUCCESS
状态码进行输出,我们就应该这样使用:
\x\Restful::SUCCESS()
依赖类:\x\Restful
方法名:code()
参数:
mixed $code
返回值:\x\Restful
对象本身
示例代码:
namespace app\http;
use x\controller\Http;
/**
* @Controller(prefix="")
*/
class Index extends Http
{
/**
* @RequestMapping(route="/", method="get", title="主页")
*/
public function index() {
// 使用XML返回结构
// 抛出/restful/default/code.php中的SUCCESS状态码
return \x\Restful::type('xml')->code(\x\Restful::SUCCESS())->callback();
}
}