2018-05-03 20:43:13 3116次浏览 2条回答 0 悬赏 10 金钱

返回json时用 return $this->asjason([...])有时会报错
用 Yii::$app->getResponse()->format = \yii\web\Response::FORMAT_JSON;return [...];没有什么问题
这两种方法有什么本质区别?

补充于 2018-08-03 16:14

回头看response 源码,重新看这个问题,发现是我有个函数重复执行了,第二次$this->asJson 传的参数 是 response 实例,不再是数组了;

  • 回答于 2018-05-04 10:29 举报

    这个你就要看源码了,引入的类库不一样

  • 回答于 2018-05-04 10:55 举报

    “返回json时用 return $this->asjason([...])有时会报错”
    具体报的什么错,是不是 不方便说?

    2 条回复
    回复于 2018-05-04 19:51 回复

    asJson内存溢出
    name PHP Fatal Error
    message Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes)
    code 1
    type yii\base\ErrorException
    file /www/wwwroot/test02/vendor/yiisoft/yii2/helpers/BaseJson.php
    line 163

    正常应返回
    {"state":"SUCCESS","url":"/uploads/images/201805/1525434256593896.jpg","title":"1525434256593896.jpg","original":"avatar.jpg","type":".jpg","size":17079}

    回复于 2018-05-25 17:42 回复

    echo phpinfo();看一下memory_limit的值是多少,你现在这个是128m。默认一般都是128m.

您需要登录后才可以回答。登录 | 立即注册
qingchen
副总裁

qingchen

注册时间:2013-09-09
最后登录:2024-03-22
在线时长:35小时12分
  • 粉丝5
  • 金钱4265
  • 威望60
  • 积分5215

热门问题