当前位置:网站首页>TP5 error reporting variable type error: array solution
TP5 error reporting variable type error: array solution
2022-04-23 06:52:00 【Collect and study by yourself】
When you are in tp5 When a method is written in the framework, an array is returned ,tp5 Will report a mistake :variable type error: array
This is because tp5 Returning arrays is not supported .
I made it up 2 A solution , Everyone depends on their actual needs , To decide which method to use .
Method 1 : Need to modify your source code
Add... Directly to the return statement json()、xml()..... Wait for the data type function you need to return
for example :
<?phpnamespace app\index\controller;use think\Db;class Index{ public function index() { $returnData=json(Db::query('select * from xtable');) return $returnData; }}
Method 2 : Do not modify the source code , Need to be revised tp5 The configuration file
Find and open tp5 In the framework “config.php” The configuration file . Find... In the configuration file
'default_return_type' => 'html'( As shown in the figure below )
Set this property to the data type you want to return . For example, it can be set to :
'default_return_type' => 'json' perhaps 'default_return_type' => 'xml'
above 2 Both methods can return results , We decide which kind of... To use according to our actual needs .
Attached ‘ThinkPHP5.0 Full development manual ’ The detailed method of this error report in the :
http://www.kancloud.cn/manual/thinkphp5/118017
版权声明
本文为[Collect and study by yourself]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230555551918.html
边栏推荐
猜你喜欢
随机推荐
ES6规范详解
模仿扇贝短文阅读页面
Leak detection and filling (I)
offset和client获取dom元素位置信息
Promise(二)
.Net Core 下使用 Quartz —— 【1】快速开始
Devexpress Gridview 添加全选列
【批量更改mysql表以及表中字段对应的编码】
swiper组件封装
百度地图基础案例
如何使用input表单向服务发送(占用较小)图片文件(body传输)?涉及到FileReader内置对象
leetcode刷题之整数加一
Mysql中的索引与视图
五个路由守卫的使用
颜色字符串转换
leetcode刷题之x的算术平方根
小程序学习笔记(一)
ASP.NET CORE JWT认证
低代码开发平台整理
1-3 NodeJS的安装之清单配置与跑项目环境