TP5内置语句如下:
$list = $RealName_model->where($where)->order(['id' => 'desc'])->field('id,real_name,mobile,is_success')->paginate($paginate['list_rows'], false, $page_config);
该数组返回的示例如下:
think\paginator\driver\Bootstrap::__set_state(array(
'simple' => false,
'items' =>
think\Collection::__set_state(array(
'items' =>
array (
0 =>
array (
'id' => 3,
'real_name' => '刘炎',
'mobile' => '15395110269',
'is_success' => 1,
'order_count' => 0,
'order_sum_money' => '0.00',
),
),
)),
'currentPage' => 1,
'lastPage' => 1,
'total' => 1,
'listRows' => 15,
'hasMore' => false,
'options' =>
array (
'var_page' => 'page',
'path' => '/api/Business/team_management.html',
'query' =>
array (
),
'fragment' => '',
'type' => 'bootstrap',
'list_rows' => 15,
'merchant_id' => 1,
'is_check' => 1,
'page' => 1,
),
'nextItem' => NULL,
))
要想将以上的数据转换成数组,就要调用toArray()方法:
$list = $list->toArray();
这是thinkPHP集成好的方法,在thinkphp/library/think/collection.php文件中定义。处理之后的值就是一个规范的数组。形式如下:
array (
'total' => 1,
'per_page' => 15,
'current_page' => 1,
'last_page' => 1,
'data' =>
array (
0 =>
array (
'id' => 3,
'real_name' => '刘先生',
'mobile' => '15388888888',
'is_success' => 1,
'order_count' => 0,
'order_sum_money' => '0.00',
),
),
)