Cakephp paginator数组错误

时间:2013-08-08 09:59:39

标签: cakephp paginator

我是CakePHP的新手,对此控制器有疑问:

function showmy($userid) {

    return $this->Voucher->find('all', array('conditions' => array('Voucher.user_id' => $userid)));

}   

public function index() {
    $this->Voucher->recursive = 0;
    $userid = $this->Session->read('Auth.User.id');
    $this->set('vouchers', $this->showmy($userid ));
}

我希望所有凭证都由用户提供的user_id。

它有效,但我收到很多错误,如:

 Warning (2): array_filter() expects parameter 1 to be array, null given     [CORE\Cake\View\Helper\PaginatorHelper.php, line 419]

也许有经验的人可以给我一些建议!

谢谢,  朱利

3 个答案:

答案 0 :(得分:0)

我认为您需要使用PaginatorComponent::paginate()才能在视图中使用PaginatorHelper。 manual

中的更多信息

答案 1 :(得分:0)

您必须在控制器中为分页

声明$ paginate数组

public $paginate = array( 'limit' => 25, 'order' => array( 'Post.title' => 'asc' ) );

paginate => array

答案 2 :(得分:0)

public function index() {
        $this->Voucher->recursive = 0;
        $userid = $this->Session->read('Auth.User.id');
        $this->Paginator->settings = array(
                    array('conditions' => array('Voucher.user_id' => $userid))
                );

        $this->set('vouchers', $this->Paginator->paginate('Voucher'));
    }