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注释掉即可

在使用Postman测试接口时遇到错误。通过检查backend
untimelogsapp.log日志,发现webcontroller.php第166行存在$enableCsrfValidation问题。解决方法是将TmisDeptController改为继承rest下的controller。调整后,确保返回JSON格式结果,需在controller中正确设置返回语句,并在backendconfigmain.php配置response为json格式。

3175

被折叠的 条评论
为什么被折叠?



