我有 10 个订阅者表,从订阅者_0 到订阅者_9,我通过订阅者模型中的自定义查询通过联合从它们获取所有数据,在函数 getAllSubscribers 中,该表执行查询并将结果返回给订阅者控制器,我设置了 $useTable = false 因为没有订阅者表,我的问题是如何在控制器中对这些数据进行分页?
作为参考,我在这里写我的查询,结果返回查询:
$query = 'SELECT * FROM (
SELECT * FROM subscriber_1
UNION
SELECT * FROM subscriber_2
UNION
SELECT * FROM subscriber_3
UNION
SELECT * FROM subscriber_4
UNION
SELECT * FROM subscriber_5
UNION
SELECT * FROM subscriber_6
UNION
SELECT * FROM subscriber_7
UNION
SELECT * FROM subscriber_8
UNION
SELECT * FROM subscriber_9
UNION
SELECT * FROM subscriber_0
) AS subscriber WHERE created > \'' . $startDate . '\' AND created < \'' . $endDate . '\'';
结果:
array(
(int) 0 => array(
'subscriber' => array(
'a_party' => '923003210861',
'subtype' => '0',
'stat' => '0',
'created' => '2012-11-26 06:53:31',
'updated' => null
)
),
(int) 1 => array(
'subscriber' => array(
'a_party' => '923005264511',
'subtype' => '0',
'stat' => '0',
'created' => '2012-11-26 06:53:31',
'updated' => null
)
)
,
.
.
.
.(int) 50 => ...
我在订阅者控制器中添加了这个
public $paginate = array(
'limit' => 10
);
我还需要添加什么?
我见过这个但没有帮助
CakePHP 将自定义查询从控制器传递到模型 paginate()
编辑:在下面添加控制器代码
$data = $this->Subscriber->getAllSubscribers();//This model method returns custom data from query
$this->paginate = array('fields' => $selectedField);
$paginatedData = $this->paginate($data);
//debug($paginatedData);
$this->set('subslist', $paginatedData);
上面的代码不起作用,我做错了什么,谢谢