做了一个API父类,但是json()没有响应结果

浏览:734 发布日期:2016/08/23 分类:ThinkPHP5专区 关键字: api
namespace api\index\controller;
use think\Db;
use think\Request;
class BaseApi
{
    protected $return = array();
    protected $msg = [
        '1' => '操作不存在或被禁用'
    ];
    public function __construct()
    {
        $request = Request::instance();
        $appkey = $request->param('appkey');
        $api_id = Db::name('api_list')->where(['appkey'=>$appkey,'status'=>1])->value('id');
        if(empty($api_id))
        {
            $this->return['code'] = 1;
            $this->return['message'] = $this->msg['1'];
            return json($this->return);   //这里返回给浏览器没东西
        }
        $info['api_id'] = $api_id;
        $info['api_action'] = $request->module().'/'.$request->controller().'/'.$request->action();
        $info['ip'] = $request->ip();
        $info['parms'] = json_encode($request->param());
        $info['action_time'] = time();
        $info['method'] = $request->method();
        $info['user_agent'] = json_encode($request->header('user-agent'));
    }

    public function index()
    {

    }

}
执行index操作走到return json($this->return);浏览器没有接受到json
最佳答案
评论( 相关
后面还有条评论,点击查看>>