首页 > 技术文章 > tp5将查询数据返回为对象转为数组

ovim 2019-08-21 10:42 原文

use think\Model;
collection()->toArray();
$result = collection(model("Menu")->order("listorder asc,id asc")->select())->toArray();


或是在模型里写
namespace app\admin\model;

class Menu extends \think\Model
{
protected $resultSetType = 'collection';
}

控制器
$result = model("Menu")->order("listorder asc,id asc")->select()->toArray();

  

参考tp5官方网站论坛:http://www.thinkphp.cn/topic/47321.html

 

推荐阅读