Cakephp paginate链接到Model中的方法

时间:2014-03-26 09:52:07

标签: cakephp cakephp-2.0

我想得到任何帮助。我想在Controller中编写分页代码,可以从Model中的方法中检索数据。请注意我使用cakephp。

这是Controller中的函数uploadDocumentForm

function uploadDocumentForm()
        {
                if(!$this->User->checkPrivilege(array(6))) {
                        throw new ForbiddenException();
                }
                $userID = $this->Session->read('userID');
                $this->set('documentList',$this->SystemParameter->getDocumentList("DOCUMENT_TYPE"));
                $this->set('studentUploadDocumentList',$this->Document->getDocumentByUserID($userID));

这是文档模型中的getDocumentByUserID函数

function getDocumentByUserID($anUserID)
        {
                return $this->find('all',array('conditions'=>array('Project.student_user_id'=>$anUserID),'order'=>array('Document.document_id'=>'desc')));
        }

那么,我如何编写与getDocumentByUserID相关联的Controller中的分页? 非常感谢你

Ponom

1 个答案:

答案 0 :(得分:1)

官方文档中涵盖in the chapter about the pagination component,请阅读。

  

如果您无法使用标准查找选项来创建   查询您需要显示您的数据,有几个选项。您可以   使用自定义查找类型。您还可以实现paginate()和   模型上的paginateCount()方法,或将它们包含在行为中   附在您的模型上。实现paginate和/或的行为   paginateCount应该实现下面定义的方法签名   使用$ model的正常附加第一个参数:

相关问题