本文整理汇总了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);
}
示例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();
}
}
示例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');
}
示例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');
}
示例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');
}
示例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');
}
示例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);
}
示例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);
}
示例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));
}
示例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));
}
示例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));
}
示例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);
}
示例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');
}
示例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);
}
示例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);
}
}