用的RestController.
namespace Home\Controller;
use Think\Controller\RestController;
class UserController extends RestController{
protected $allowMethod = array('get','post','put'); // REST允许的请求类型列表
protected $allowType = array('html','xml','json'); // REST允许请求的资源类型列表
Public function read_get_html(){
$data = array("status"=>1,"info"=>"ok");
$this->response($data,'json');
// 输出id为1的Info的html页面
}
Public function read_get_xml(){
// 输出id为1的Info的XML数据
}
Public function read_xml(){
// 输出id为1的Info的XML数据
}
Public function read_json(){
// 输出id为1的Info的json数据
}
} 最佳答案