当前位置: 首页>>代码示例>>PHP>>正文


PHP Controller::paginate方法代码示例

本文整理汇总了PHP中Controller::paginate方法的典型用法代码示例。如果您正苦于以下问题:PHP Controller::paginate方法的具体用法?PHP Controller::paginate怎么用?PHP Controller::paginate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Controller的用法示例。


在下文中一共展示了Controller::paginate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: paginate

 /**
  * Handles automatic pagination of model records.
  *
  * @overwrite to support defaults like limit, querystring settings
  * @param Model|string $object Model to paginate (e.g: model instance, or 'Model', or 'Model.InnerModel')
  * @param string|array $scope Conditions to use while paginating
  * @param array $whitelist List of allowed options for paging
  * @return array Model query results
  */
 public function paginate($object = null, $scope = array(), $whitelist = array())
 {
     if ($defaultSettings = (array) Configure::read('Paginator')) {
         $this->paginate += $defaultSettings;
     }
     return parent::paginate($object, $scope, $whitelist);
 }
开发者ID:Jony01,项目名称:LLD,代码行数:16,代码来源:MyController.php

示例2: _scaffoldIndex

 /**
  * Renders index action of scaffolded model.
  *
  * @param array $params Parameters for scaffolding
  * @return mixed A rendered view listing rows from Models database table
  */
 protected function _scaffoldIndex($params)
 {
     if ($this->controller->beforeScaffold('index')) {
         $this->ScaffoldModel->recursive = 0;
         $this->controller->set(Inflector::variable($this->controller->name), $this->controller->paginate());
         $this->controller->render($this->request['action'], $this->layout);
     } elseif ($this->controller->scaffoldError('index') === false) {
         return $this->_scaffoldError();
     }
 }
开发者ID:morrislaptop,项目名称:advindex,代码行数:16,代码来源:Scaffold.php

示例3: lookup

 /**
  * List users with filter capability as defined in User::$filterArgs
  *
  * This will be useful for ajax autocompletion
  */
 public function lookup(Controller $controller)
 {
     $request = $controller->request;
     $controller->Prg->commonProcess();
     $controller->User->Behaviors->attach('Users.UserApiResultFormatter');
     $controller->paginate = array('fields' => array('id', 'username', 'name', 'website', 'image', 'bio', 'timezone', 'status', 'created', 'updated'), 'contain' => array('Role' => array('fields' => array('id', 'title', 'alias'))), 'conditions' => $controller->User->parseCriteria($request->query));
     $users = $controller->paginate();
     $controller->set('_rootNode', 'users');
     $controller->set('user', $users);
     $controller->set('_serialize', 'user');
 }
开发者ID:saydulk,项目名称:croogo,代码行数:16,代码来源:UserApiComponent.php

示例4: lookup

 /**
  * List nodes with filter capability as defined in Node::$filterArgs
  *
  * This will be useful for ajax autocompletion
  */
 public function lookup(Controller $controller)
 {
     $request = $controller->request;
     $controller->Prg->commonProcess();
     $Node = $controller->{$controller->modelClass};
     $Node->Behaviors->attach('Nodes.NodeApiResultFormatter');
     $controller->paginate = array('fields' => array('id', 'parent_id', 'type', 'user_id', 'title', 'slug', 'body', 'excerpt', 'status', 'promote', 'path', 'terms', 'created', 'updated', 'publish_start', 'publish_end'), 'contain' => array('User', 'Meta', 'Taxonomy'), 'conditions' => $Node->parseCriteria($request->query));
     $nodes = $controller->paginate();
     $controller->set('_rootNode', 'nodes');
     $controller->set('node', $nodes);
     $controller->set('_serialize', 'node');
 }
开发者ID:saydulk,项目名称:croogo,代码行数:17,代码来源:NodeApiComponent.php

示例5: testPagination

 public function testPagination()
 {
     $this->markTestSkipped('Needs revision');
     $objController = new Controller(new CakeRequest('/'), new CakeResponse());
     $objController->layout = 'ajax';
     $objController->uses = array('User');
     $objController->constructClasses();
     $objController->request->url = '/';
     $objController->paginate = array('fields' => array('username'), 'contain' => false, 'link' => array('Profile' => array('fields' => array('biography'))), 'limit' => 2);
     $arrayResult = $objController->paginate('User');
     $this->assertEquals($objController->params['paging']['User']['count'], 4, 'Paging: total records count: %s');
     // Pagination with order on a row from table joined with Linkable
     $objController->paginate = array('fields' => array('id'), 'contain' => false, 'link' => array('Profile' => array('fields' => array('user_id'))), 'limit' => 2, 'order' => 'Profile.user_id DESC');
     $arrayResult = $objController->paginate('User');
     $arrayExpected = array(0 => array('User' => array('id' => 4), 'Profile' => array('user_id' => 4)), 1 => array('User' => array('id' => 3), 'Profile' => array('user_id' => 3)));
     $this->assertEquals($arrayResult, $arrayExpected, 'Paging with order on join table row: %s');
     // Pagination without specifying any fields
     $objController->paginate = array('contain' => false, 'link' => array('Profile'), 'limit' => 2, 'order' => 'Profile.user_id DESC');
     $arrayResult = $objController->paginate('User');
     $this->assertEquals($objController->params['paging']['User']['count'], 4, 'Paging without any field lists: total records count: %s');
 }
开发者ID:lorenzo,项目名称:linkable,代码行数:21,代码来源:LinkableBehaviorTest.php

示例6: _indexAction

 /**
  * Generic index action
  *
  * Triggers the following callbacks
  *	- Crud.init
  *	- Crud.beforePaginate
  *	- Crud.afterPaginate
  *	- Crud.beforeRender
  *
  * @return void
  */
 protected function _indexAction()
 {
     $Paginator = $this->_Collection->load('Paginator');
     // Copy pagination settings from the controller
     if (!empty($this->_controller->paginate)) {
         $Paginator->settings = array_merge($Paginator->settings, $this->_controller->paginate);
     }
     if (!empty($Paginator->settings[$this->_modelName]['findType'])) {
         $findMethod = $Paginator->settings[$this->_modelName]['findType'];
     } elseif (!empty($Paginator->settings['findType'])) {
         $findMethod = $Paginator->settings['findType'];
     } else {
         $findMethod = $this->_getFindMethod(null, 'all');
     }
     $subject = $this->trigger('beforePaginate', compact('findMethod'));
     // Copy pagination settings from the controller
     if (!empty($this->_controller->paginate)) {
         $Paginator->settings = array_merge($Paginator->settings, $this->_controller->paginate);
     }
     // If pagination settings is using ModelAlias modify that
     if (!empty($Paginator->settings[$this->_modelName])) {
         $Paginator->settings[$this->_modelName][0] = $subject->findMethod;
         $Paginator->settings[$this->_modelName]['findType'] = $subject->findMethod;
     } else {
         // Or just work directly on the root key
         $Paginator->settings[0] = $subject->findMethod;
         $Paginator->settings['findType'] = $subject->findMethod;
     }
     // Push the paginator settings back to Controller
     $this->_controller->paginate = $Paginator->settings;
     // Do the pagination
     $items = $this->_controller->paginate($this->_model);
     $subject = $this->trigger('afterPaginate', compact('items'));
     $items = $subject->items;
     // Make sure to cast any iterators to array
     if ($items instanceof Iterator) {
         $items = iterator_to_array($items);
     }
     $this->_controller->set(compact('items'));
     $this->trigger('beforeRender');
 }
开发者ID:nodesagency,项目名称:Platform-Crud-Plugin,代码行数:52,代码来源:CrudComponent.php

示例7: paginate

 /**
  * Over write of core paginate method
  * to handle auto filtering.
  *
  * @param string
  * @param array
  * @param array
  */
 public function paginate($object = null, $scope = array(), $whitelist = array())
 {
     $this->request->params = array_merge($this->request->params, Router::parse(urldecode($this->request->here)));
     $this->_handlePaginatorSorting();
     $this->_handlePaginatorFiltering($object);
     $this->Paginator->settings = $this->paginate;
     return parent::paginate($object, $scope, $whitelist);
 }
开发者ID:ajayphp,项目名称:Zuha,代码行数:16,代码来源:AppController.php

示例8: testPaginateMaxLimit

 /**
  * testPaginateMaxLimit
  *
  * @return void
  */
 public function testPaginateMaxLimit()
 {
     $Controller = new Controller($this->request);
     $Controller->uses = array('PaginatorControllerPost', 'ControllerComment');
     $Controller->passedArgs[] = '1';
     $Controller->constructClasses();
     $Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '1000');
     $result = $Controller->paginate('PaginatorControllerPost');
     $this->assertEquals($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 100);
     $Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '1000', 'maxLimit' => 1000);
     $result = $Controller->paginate('PaginatorControllerPost');
     $this->assertEquals($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 100);
     $Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '10');
     $result = $Controller->paginate('PaginatorControllerPost');
     $this->assertEquals($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 10);
     $Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '1000');
     $Controller->paginate = array('maxLimit' => 2000, 'paramType' => 'named');
     $result = $Controller->paginate('PaginatorControllerPost');
     $this->assertEquals($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 1000);
     $Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '5000');
     $result = $Controller->paginate('PaginatorControllerPost');
     $this->assertEquals($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 2000);
 }
开发者ID:Chromedian,项目名称:inventory,代码行数:28,代码来源:PaginatorComponentTest.php

示例9: testDefaultPaginateParams

 /**
  * testDefaultPaginateParams method
  *
  * @access public
  * @return void
  */
 function testDefaultPaginateParams()
 {
     $Controller = new Controller();
     $Controller->modelClass = 'ControllerPost';
     $Controller->params['url'] = array();
     $Controller->paginate = array('order' => 'ControllerPost.id DESC');
     $Controller->constructClasses();
     $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
     $this->assertEqual($Controller->params['paging']['ControllerPost']['defaults']['order'], 'ControllerPost.id DESC');
     $this->assertEqual($Controller->params['paging']['ControllerPost']['options']['order'], 'ControllerPost.id DESC');
     $this->assertEqual($results, array(3, 2, 1));
 }
开发者ID:evrard,项目名称:cakephp2x,代码行数:18,代码来源:controller.test.php

示例10: testPaginateOrderVirtualFieldSharedWithRealField

 /**
  * test paginate() and virtualField overlapping with real fields.
  *
  * @return void
  */
 public function testPaginateOrderVirtualFieldSharedWithRealField()
 {
     $Controller = new Controller($this->request);
     $Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment');
     $Controller->constructClasses();
     $Controller->PaginatorControllerComment->virtualFields = array('title' => 'PaginatorControllerComment.comment');
     $Controller->PaginatorControllerComment->bindModel(array('belongsTo' => array('PaginatorControllerPost' => array('className' => 'PaginatorControllerPost', 'foreignKey' => 'article_id'))), false);
     $Controller->paginate = array('fields' => array('PaginatorControllerComment.id', 'title', 'PaginatorControllerPost.title'));
     $Controller->passedArgs = array('sort' => 'PaginatorControllerPost.title', 'dir' => 'asc');
     $result = $Controller->paginate('PaginatorControllerComment');
     $this->assertEquals(Set::extract($result, '{n}.PaginatorControllerComment.id'), array(1, 2, 3, 4, 5, 6));
 }
开发者ID:rufl,项目名称:ATP,代码行数:17,代码来源:PaginatorComponentTest.php

示例11: testPaginate

 /**
  * testPaginate method
  *
  * @access public
  * @return void
  */
 function testPaginate()
 {
     $Controller = new Controller();
     $Controller->uses = array('Article');
     $Controller->passedArgs[] = '1';
     $Controller->params['url'] = array();
     $Controller->constructClasses();
     $Controller->paginate = array('Article' => array('fields' => array('title'), 'contain' => array('User(user)')));
     $result = $Controller->paginate('Article');
     $expected = array(array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)), array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)), array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)));
     $this->assertEqual($result, $expected);
     $r = $Controller->Article->find('all');
     $this->assertTrue(Set::matches('/Article[id=1]', $r));
     $this->assertTrue(Set::matches('/User[id=1]', $r));
     $this->assertTrue(Set::matches('/Tag[id=1]', $r));
     $Controller->paginate = array('Article' => array('contain' => array('Comment(comment)' => 'User(user)'), 'fields' => array('title')));
     $result = $Controller->paginate('Article');
     $expected = array(array('Article' => array('title' => 'First Article', 'id' => 1), 'Comment' => array(array('comment' => 'First Comment for First Article', 'user_id' => 2, 'article_id' => 1, 'User' => array('user' => 'nate')), array('comment' => 'Second Comment for First Article', 'user_id' => 4, 'article_id' => 1, 'User' => array('user' => 'garrett')), array('comment' => 'Third Comment for First Article', 'user_id' => 1, 'article_id' => 1, 'User' => array('user' => 'mariano')), array('comment' => 'Fourth Comment for First Article', 'user_id' => 1, 'article_id' => 1, 'User' => array('user' => 'mariano')))), array('Article' => array('title' => 'Second Article', 'id' => 2), 'Comment' => array(array('comment' => 'First Comment for Second Article', 'user_id' => 1, 'article_id' => 2, 'User' => array('user' => 'mariano')), array('comment' => 'Second Comment for Second Article', 'user_id' => 2, 'article_id' => 2, 'User' => array('user' => 'nate')))), array('Article' => array('title' => 'Third Article', 'id' => 3), 'Comment' => array()));
     $this->assertEqual($result, $expected);
     $r = $Controller->Article->find('all');
     $this->assertTrue(Set::matches('/Article[id=1]', $r));
     $this->assertTrue(Set::matches('/User[id=1]', $r));
     $this->assertTrue(Set::matches('/Tag[id=1]', $r));
     $Controller->Article->unbindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User'), 'hasAndBelongsToMany' => array('Tag')), false);
     $Controller->Article->bindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User')), false);
     $Controller->paginate = array('Article' => array('contain' => array('Comment(comment)', 'User(user)'), 'fields' => array('title')));
     $r = $Controller->paginate('Article');
     $this->assertTrue(Set::matches('/Article[id=1]', $r));
     $this->assertTrue(Set::matches('/User[id=1]', $r));
     $this->assertTrue(Set::matches('/Comment[article_id=1]', $r));
     $this->assertFalse(Set::matches('/Comment[id=1]', $r));
     $r = $this->Article->find('all');
     $this->assertTrue(Set::matches('/Article[id=1]', $r));
     $this->assertTrue(Set::matches('/User[id=1]', $r));
     $this->assertTrue(Set::matches('/Comment[article_id=1]', $r));
     $this->assertTrue(Set::matches('/Comment[id=1]', $r));
 }
开发者ID:evrard,项目名称:cakephp2x,代码行数:43,代码来源:containable.test.php

示例12: testPaginateBackwardsCompatibility

 /**
  * test that using Controller::paginate() falls back to PaginatorComponent
  *
  * @return void
  */
 function testPaginateBackwardsCompatibility()
 {
     $request = new CakeRequest('controller_posts/index');
     $request->params['pass'] = $request->params['named'] = array();
     $Controller = new Controller($request);
     $Controller->uses = array('ControllerPost', 'ControllerComment');
     $Controller->passedArgs[] = '1';
     $Controller->params['url'] = array();
     $Controller->constructClasses();
     $expected = array('page' => 1, 'limit' => 20, 'maxLimit' => 100, 'paramType' => 'named');
     $this->assertEqual($Controller->paginate, $expected);
     $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
     $this->assertEqual($results, array(1, 2, 3));
     $Controller->passedArgs = array();
     $Controller->paginate = array('limit' => '-1');
     $this->assertEqual($Controller->paginate, array('limit' => '-1'));
     $Controller->paginate('ControllerPost');
     $this->assertIdentical($Controller->params['paging']['ControllerPost']['page'], 1);
     $this->assertIdentical($Controller->params['paging']['ControllerPost']['pageCount'], 3);
     $this->assertIdentical($Controller->params['paging']['ControllerPost']['prevPage'], false);
     $this->assertIdentical($Controller->params['paging']['ControllerPost']['nextPage'], true);
 }
开发者ID:robotarmy,项目名称:Phog,代码行数:27,代码来源:controller.test.php

示例13: testPagination

 public function testPagination()
 {
     $objController = new Controller(new CakeRequest(), new CakeResponse());
     $objController->layout = 'ajax';
     $objController->uses = ['LinkableUser'];
     $objController->constructClasses();
     $objController->request->url = '/';
     $objController->paginate = ['fields' => ['username'], 'contain' => false, 'link' => ['LinkableProfile' => ['fields' => ['biography']]], 'limit' => 2];
     $arrayResult = $objController->paginate('LinkableUser');
     $this->assertEquals(4, $objController->params['paging']['LinkableUser']['count'], 'Paging: total records count: %s');
     // Pagination with order on a row from table joined with Linkable
     $objController->paginate = ['fields' => ['id'], 'contain' => false, 'link' => ['LinkableProfile' => ['fields' => ['user_id']]], 'limit' => 2, 'order' => 'LinkableProfile.user_id DESC'];
     $arrayResult = $objController->paginate('LinkableUser');
     $arrayExpected = [0 => ['LinkableUser' => ['id' => 4], 'LinkableProfile' => ['user_id' => 4]], 1 => ['LinkableUser' => ['id' => 3], 'LinkableProfile' => ['user_id' => 3]]];
     $this->assertEquals($arrayExpected, $arrayResult, 'Paging with order on join table row: %s');
     // Pagination without specifying any fields
     $objController->paginate = ['contain' => false, 'link' => ['LinkableProfile'], 'limit' => 2, 'order' => 'LinkableProfile.user_id DESC'];
     $arrayResult = $objController->paginate('LinkableUser');
     $this->assertEquals(4, $objController->params['paging']['LinkableUser']['count'], 'Paging without any field lists: total records count: %s');
 }
开发者ID:ByMyHandsOnly,项目名称:BMHO_Web,代码行数:20,代码来源:LinkableBehaviorTest.php

示例14: testPaginateBackwardsCompatibility

 /**
  * test that using Controller::paginate() falls back to PaginatorComponent
  *
  * @return void
  */
 public function testPaginateBackwardsCompatibility()
 {
     $request = new CakeRequest('controller_posts/index');
     $request->params['pass'] = $request->params['named'] = array();
     $response = $this->getMock('CakeResponse', array('httpCodes'));
     $Controller = new Controller($request, $response);
     $Controller->uses = array('ControllerPost', 'ControllerComment');
     $Controller->passedArgs[] = '1';
     $Controller->params['url'] = array();
     $Controller->constructClasses();
     $expected = array('page' => 1, 'limit' => 20, 'maxLimit' => 100, 'paramType' => 'named');
     $this->assertEquals($expected, $Controller->paginate);
     $results = Hash::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
     $this->assertEquals(array(1, 2, 3), $results);
     $Controller->passedArgs = array();
     $Controller->paginate = array('limit' => '-1');
     $this->assertEquals(array('limit' => '-1'), $Controller->paginate);
     $Controller->paginate('ControllerPost');
     $this->assertSame($Controller->params['paging']['ControllerPost']['page'], 1);
     $this->assertSame($Controller->params['paging']['ControllerPost']['pageCount'], 3);
     $this->assertSame($Controller->params['paging']['ControllerPost']['prevPage'], false);
     $this->assertSame($Controller->params['paging']['ControllerPost']['nextPage'], true);
 }
开发者ID:abhinand4858,项目名称:ProgrammedV,代码行数:28,代码来源:ControllerTest.php

示例15: testPaginate

 public function testPaginate()
 {
     $Controller = new Controller();
     $Controller->uses = array('TestAddress');
     $Controller->params['url'] = array();
     $Controller->constructClasses();
     $Controller->paginate = array('TestAddress' => array('near', 'fields' => array('address'), 'limit' => 2, 'address' => '1209 La Brad Lane, Tampa, FL'));
     $result = $Controller->paginate('TestAddress');
     $this->assertTrue(!empty($result));
     if (!empty($result)) {
         $result = Set::combine($result, '/' . $this->Address->alias . '/address', '/' . $this->Address->alias . '/distance');
         foreach ($result as $key => $distance) {
             $result[$key] = round($distance, 3);
         }
         $expected = array('14348 N Rome Ave, Tampa, 33613 FL' => 0.257, '1180 Magdalene Hill, Florida, US' => 0.499);
         $this->assertEqual($result, $expected);
     }
     $Controller->paginate = array('TestAddress' => array('near', 'fields' => array('address'), 'limit' => 2, 'address' => '1209 La Brad Lane, Tampa, FL', 'page' => 2));
     $result = $Controller->paginate('TestAddress');
     $this->assertTrue(!empty($result));
     if (!empty($result)) {
         $result = Set::combine($result, '/' . $this->Address->alias . '/address', '/' . $this->Address->alias . '/distance');
         foreach ($result as $key => $distance) {
             $result[$key] = round($distance, 3);
         }
         $expected = array('9106 El Portal Dr, Tampa, FL' => 5.331);
         $this->assertEqual($result, $expected);
     }
     $Controller->paginate = array('TestAddress' => array('near', 'fields' => array('address'), 'limit' => 2, 'address' => '1209 La Brad Lane, Tampa, FL', 'unit' => 'm'));
     $result = $Controller->paginate('TestAddress');
     $this->assertTrue(!empty($result));
     if (!empty($result)) {
         $result = Set::combine($result, '/' . $this->Address->alias . '/address', '/' . $this->Address->alias . '/distance');
         foreach ($result as $key => $distance) {
             $result[$key] = round($distance, 3);
         }
         $expected = array('14348 N Rome Ave, Tampa, 33613 FL' => 0.16, '1180 Magdalene Hill, Florida, US' => 0.31);
         $this->assertEqual($result, $expected);
     }
     $Controller->paginate = array('TestAddress' => array('near', 'fields' => array('address'), 'limit' => 2, 'address' => '1209 La Brad Lane, Tampa, FL', 'unit' => 'm', 'distance' => 0.25));
     $result = $Controller->paginate('TestAddress');
     $this->assertTrue(!empty($result));
     if (!empty($result)) {
         $result = Set::combine($result, '/' . $this->Address->alias . '/address', '/' . $this->Address->alias . '/distance');
         foreach ($result as $key => $distance) {
             $result[$key] = round($distance, 3);
         }
         $expected = array('14348 N Rome Ave, Tampa, 33613 FL' => 0.16);
         $this->assertEqual($result, $expected);
     }
 }
开发者ID:billabong,项目名称:geocode,代码行数:51,代码来源:geocodable.test.php


注:本文中的Controller::paginate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。