tp5数据输出

法一:系统配置

    'default_return_type'=>'json'

法二:输出设置

    namespace app\index\controller;
    class Index 
    {
        public function index()
        {
            $data = ['name'=>'thinkphp','url'=>'thinkphp.cn'];
            // 指定json数据输出
            return json(['data'=>$data,'code'=>1,'message'=>'操作完成']);
        }
    }

或者指定输出XML类型数据:

    namespace app\index\controller;
    class Index 
    {
        public function index()
        {
            $data = ['name'=>'thinkphp','url'=>'thinkphp.cn'];
            // 指定xml数据输出
            return xml(['data'=>$data,'code'=>1,'message'=>'操作完成']);
        }
    }

核心支持的数据类型包括view、xml、json和jsonp,其他类型的需要自己扩展。

 

posted @ 2017-09-05 11:49  侠岚之弋痕夕  阅读(1527)  评论(0编辑  收藏  举报
Where is the starting point, we don't have a choice, but the destination where we can pursue!