zoukankan      html  css  js  c++  java
  • thinkphp 响应对象

    <?php
    namespace appadmincontroller;
    use thinkRequest;
    class Index{
        public function index(Request $request){
            $res=[
                'code'=>200,
                'result'=>[
                    'list'=>[1,2,3,4,5]
                ]
            ];
            return var_dump($res);
        }
    }
    ?>

    页面返回内容,用return

    return '123';代替echo '123';返回字符串

    返回类型的控制

    thinkphp 下 convention.php  'default_return_type'控制,默认输出类型

    使用动态配置,返回json格式

    <?php
    namespace appadmincontroller;
    use thinkRequest;
    use thinkConfig;
    class Index{
        public function index(Request $request){
            $res=[
                'code'=>200,
                'result'=>[
                    'list'=>[1,2,3,4,5]
                ]
            ];
            Config::set('default_return_type','json');
            return $res;
        }
    }
    ?>

    可以新建api模块,设置默认返回类型为json;

    conf/api/config.php

    <?php
    return [
    'default_return_type'=>'json'
    ];
    ?>
  • 相关阅读:
    C# macro function via #define __FILE__ __LINE__ ___FUNCTION__ __DATE__ __TIME__
    3
    2月23号
    3月26
    impala故障
    2月3号日更
    HDFS某个节点的磁盘满了
    3月2
    mq集群
    3月3
  • 原文地址:https://www.cnblogs.com/lgxtry/p/9139042.html
Copyright © 2011-2022 走看看