tp5使用模型查询的select结果集不能用json返回

浏览:2007 发布日期:2017/08/29 分类:求助交流
使用模型的select查询的结果集
用json方法return返回提示如下

[0] Exception in Json.php line 36
Failed calling app\api\model\Product::jsonSerialize()

* @access protected
* @param mixed $data 要处理的数据
* @return mixed
* @throws \Exception
*/
protected function output($data)
{
try {
// 返回JSON数据格式到客户端 包含状态信息
$data = json_encode($data, $this->options['json_encode_param']);

if ($data === false) {
throw new \InvalidArgumentException(json_last_error_msg());
}

return $data;
} catch (\Exception $e) {
if ($e->getPrevious()) {
throw $e->getPrevious();





代码

public function index()
{
//分页
$pageno = $this->request->post('pageno',1,'intval');
$pagesize = $this->request->post('pagesize',2,'intval');
$pageno = $pageno - 1;
//获取列表数据
$where = ['is_del'=>0];
$list = Product::where($where)->limit($pageno*$pagesize,$pagesize)->select();
//echo "<pre>";print_r(array_values($list));exit;
//$list = array('id'=>1,'list'=>$list);
return $this->retJson(['list'=>$list]);
}
最佳答案
评论( 相关
后面还有条评论,点击查看>>