当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
TypeScript(下)
freeCodeCamp----prob_calculator练习
手动实现简单的Promise及其基础功能
Leak detection and vacancy filling (IX) -- Procedure
Leak detection and filling (I)
Offset et client pour obtenir des informations sur l'emplacement des éléments Dom
常用网站汇总
条形码与二维码的生成
Promise(三)
自用学习笔记-connectingString配置
C# 监听WMI事件
ASP.NET CORE3.1 Identity注册用户后登录失败的解决方案
自用学习笔记-连接式与非连接式访问数据库
写一个正则
swiper组件封装
百度地图案例-缩放组件、地图比例组件
ES6规范详解
五个路由守卫的使用
.Net Core3.1 使用 RazorEngine.NetCore 制作实体生成器 (MVC网页版)
七牛上传图片(前台JS+后台C#API获取token)