rest使用问题

浏览:652 发布日期:2015/06/22 分类:求助交流 关键字: rest
使用一下代码构建rest资源请求控制器,但是allowMethod是无效的,即便我写智能使用POST请求,其他请求依然可以生效!!<?php
namespace Home\Controller;
use Think\Controller\RestController;
Class CommonController extends RestController {
    
    protected $allowMethod    = array('post'); // Rest允许的请求类型列表
        
     public function rest() {
         $method=$this->_method."_json";
         $result=$this->$method();
         $this->response($result,"json");
     }
    
    private function get_json(){
        $data['status']=1;
        $data['info']="就是个测试get";
        return $data;        
    }
    private function post_json(){
        // 输出id为1的Info的XML数据
        $data['status']=1;
        $data['info']="就是个测试post";
        return $data;
    }
    private function put_json(){
        $data['status']=1;
        $data['info']="就是个测试put";
        return $data;
    }
    private function delete_json(){
        $data['status']=1;
        $data['info']="就是个测试delete";
        return $data;
    }
    
}
最佳答案
评论( 相关
后面还有条评论,点击查看>>