postman测试接口产生json格式的接口报错调试
1.postman报错
2.解决方法:
打开backend\runtime\logs\app.log文件,找到刚才执行的log在最后一行
web\controller.php中166行有问题
(web\controller.php中将 $enableCsrfValidation设为了true)
解决方法:在TmisDeptController中,将controller修改为继承rest下的controller(因为rest下的controller中没有将以上变量设为true)
3.(原来的程序)
(修改后的程序)
4.ok
5.如果postman想要返回json格式的结果
需要将controller中return $model
6.还是报错---》app.log
解决方法:需要在backend\config\main.php修改为一下:添加一下response信息,设置response返回格式为json
7.ok:返回json格式
8.还可以将controller中return改为
return \yii\helpers\Json::encode(['items' => [$model],'code'=>123]);
但是需要将main.php中的response注释掉即可