本文整理汇总了PHP中Zend\Paginator\Paginator::setCache方法的典型用法代码示例。如果您正苦于以下问题:PHP Paginator::setCache方法的具体用法?PHP Paginator::setCache怎么用?PHP Paginator::setCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Paginator\Paginator
的用法示例。
在下文中一共展示了Paginator::setCache方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
$this->select = new Sql\Select();
$this->select->from('test');
$this->testCollection = range(1, 101);
$this->paginator = new Paginator\Paginator(new Paginator\Adapter\ArrayAdapter($this->testCollection));
$this->config = Config\Factory::fromFile(__DIR__ . '/_files/config.xml', true);
$this->cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0));
Paginator\Paginator::setCache($this->cache);
$this->_restorePaginatorDefaults();
}
示例2: indexAction
/**
* Mostra os posts cadastrados
* @return void
*/
public function indexAction()
{
$adapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
$sql = new Sql($adapter);
$select = $sql->select()->from('posts');
$paginatorAdapter = new PaginatorDbSelectAdapter($select, $sql);
$paginator = new Paginator($paginatorAdapter);
$paginator->setCurrentPageNumber($this->params()->fromRoute('page'));
$paginator->setItemCountPerPage($this->params()->fromRoute('itens', 50));
$cache = $this->getServiceLocator()->get('Cache');
$paginator->setCache($cache);
return new ViewModel(array('posts' => $paginator));
}
示例3: indexAction
/**
* Mostra os posts cadastrados
* @return void
*/
public function indexAction()
{
$post = $this->getTable('Application\\Model\\Post');
$sql = $post->getSql();
$select = $sql->select();
$paginatorAdapter = new PaginatorDbSelectAdapter($select, $sql);
$paginator = new Paginator($paginatorAdapter);
$cache = $this->getServiceLocator()->get('Cache');
$cache = $this->getService('Cache');
$paginator->setCache($cache);
$paginator->setCurrentPageNumber($this->params()->fromRoute('page'));
$paginator->setItemCountPerPage(10);
return new ViewModel(array('posts' => $paginator));
}
示例4: setUp
protected function setUp()
{
if (!extension_loaded('pdo_sqlite')) {
$this->markTestSkipped('Pdo_Sqlite extension is not loaded');
}
$this->_adapter = new DbAdapter\Adapter(array('driver' => 'Pdo_Sqlite', 'database' => __DIR__ . '/_files/test.sqlite'));
$this->_query = new Sql\Select();
$this->_query->from('test');
$this->_testCollection = range(1, 101);
$this->_paginator = Paginator\Paginator::factory($this->_testCollection);
$this->_config = Config\Factory::fromFile(__DIR__ . '/_files/config.xml', true);
$this->_cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0));
Paginator\Paginator::setCache($this->_cache);
$this->_restorePaginatorDefaults();
}
示例5: setUp
protected function setUp()
{
if (!extension_loaded('pdo_sqlite')) {
$this->markTestSkipped('Pdo_Sqlite extension is not loaded');
}
$this->_adapter = new \Zend\Db\Adapter\Pdo\Sqlite(array('dbname' => __DIR__ . '/_files/test.sqlite'));
$this->_query = $this->_adapter->select()->from('test');
$this->_testCollection = range(1, 101);
$this->_paginator = Paginator\Paginator::factory($this->_testCollection);
$this->_config = new Config\Xml(__DIR__ . '/_files/config.xml');
$this->_cache = CacheFactory::factory(array('adapter' => array('name' => 'filesystem', 'options' => array('ttl' => 3600, 'cache_dir' => $this->_getTmpDir())), 'plugins' => array(array('name' => 'serializer', 'options' => array('serializer' => 'php_serialize')))));
$this->_cache->clear(CacheAdapter::MATCH_ALL);
Paginator\Paginator::setCache($this->_cache);
$this->_restorePaginatorDefaults();
}
示例6: setUp
protected function setUp()
{
if (!extension_loaded('pdo_sqlite')) {
$this->markTestSkipped('Pdo_Sqlite extension is not loaded');
}
$this->_adapter = new \Zend\Db\Adapter\Pdo\Sqlite(array('dbname' => __DIR__ . '/_files/test.sqlite'));
$this->_query = $this->_adapter->select()->from('test');
$this->_testCollection = range(1, 101);
$this->_paginator = Paginator\Paginator::factory($this->_testCollection);
$this->_config = Config\Factory::fromFile(__DIR__ . '/_files/config.xml', true);
$this->_cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0));
$this->_cache->clear(CacheAdapter::MATCH_ALL);
Paginator\Paginator::setCache($this->_cache);
$this->_restorePaginatorDefaults();
}
示例7: createService
/**
* @author VanCK
* @param ServiceLocatorInterface $serviceLocator
* @return \Zend\Cache\StorageFactory
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$cache = StorageFactory::factory(array('adapter' => array('name' => 'filesystem', 'options' => array('cache_dir' => BASE_PATH . '/data/cache', 'ttl' => 100)), 'plugins' => array(array('name' => 'serializer', 'options' => []))));
\Zend\Paginator\Paginator::setCache($cache);
return $cache;
}
示例8: getPaginatedResult
/**
* An internal method for getting paginated results from querybuilder
* @param QueryBuilder $queryBuilder
* @param PaginationParameters $paginationParameters
* @param $resultKey Deprecated, use HIDDEN keyword instead
* @return \Zend\Paginator\Paginator
*/
public function getPaginatedResult(QueryBuilder $queryBuilder, PaginationParameters $paginationParameters, $resultKey = null)
{
if ($paginationParameters->getOrder() != null && $paginationParameters->getSort() != null) {
if (!is_array($paginationParameters->getSort()) && !is_array($paginationParameters->getOrder())) {
$sort = array($paginationParameters->getSort());
$order = array($paginationParameters->getOrder());
} else {
if (count($paginationParameters->getSort()) != count($paginationParameters->getOrder())) {
throw new \InvalidArgumentException('Sort and order arrays must be the same length');
}
$sort = $paginationParameters->getSort();
$order = $paginationParameters->getOrder();
}
foreach ($sort as $key => $oneSortField) {
if (!strstr($oneSortField, '.')) {
$alias = $queryBuilder->getRootAlias() . '.';
} else {
$alias = '';
}
$queryBuilder->addOrderBy($alias . $oneSortField, $order[$key]);
}
}
if ($paginationParameters->getFilters() != null) {
foreach ($paginationParameters->getFilters() as $field => $value) {
if ($value == '' || $queryBuilder->getParameter($field) != null) {
continue;
}
if (!strstr($field, '.')) {
$entityField = $queryBuilder->getRootAlias() . '.' . $field;
} else {
$entityField = $field;
}
if (is_array($value)) {
$queryBuilder->andWhere($entityField . ' IN (\'' . implode("', '", $value) . '\')');
} else {
$queryBuilder->andWhere($entityField . ' = :' . str_replace('.', '_', $field))->setParameter(str_replace('.', '_', $field), $value);
}
}
}
if ($this->usedPaginator == null) {
$paginatorTool = new \Doctrine\ORM\Tools\Pagination\Paginator($queryBuilder);
} else {
$paginatorTool = $this->usedPaginator;
}
$paginator = new Paginator(new Adapter\DoctrinePaginator($paginatorTool));
$paginator->setItemCountPerPage($paginationParameters->getItemCountPerPage());
$paginator->setCurrentPageNumber($paginationParameters->getCurrentPageNumber());
if ($paginationParameters->getCache() != null) {
$paginator->setCache($paginationParameters->getCache());
}
if ($resultKey !== null) {
foreach ($paginator as &$itemElement) {
$itemElement = $itemElement[$resultKey];
}
}
return $paginator;
}