本文整理汇总了PHP中Zend_Paginator::setCacheEnabled方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Paginator::setCacheEnabled方法的具体用法?PHP Zend_Paginator::setCacheEnabled怎么用?PHP Zend_Paginator::setCacheEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Paginator
的用法示例。
在下文中一共展示了Zend_Paginator::setCacheEnabled方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testWithCacheDisabled
public function testWithCacheDisabled()
{
$this->_paginator->setCacheEnabled(false);
$this->_paginator->setCurrentPageNumber(1)->getCurrentItems();
$cachedPageItems = $this->_paginator->getPageItemCache();
$expected = new \ArrayIterator(range(1, 10));
$this->assertEquals(array(), $cachedPageItems);
$pageItems = $this->_paginator->getCurrentItems();
$this->assertEquals($expected, $pageItems);
}
示例2: fetchAll
/**
* Retorna vários registros
*
* @param string|array $where OPTIONAL An SQL WHERE clause
* @param string|array $order OPTIONAL An SQL ORDER clause.
* @param int $count OPTIONAL An SQL LIMIT count.
* @param int $offset OPTIONAL An SQL LIMIT offset.
*
* @return array|null Lista de registros ou nulo se não localizar nenhum
*/
public function fetchAll($where = null, $order = null, $count = null, $offset = null)
{
// Cria a assinatura da consulta
if ($where instanceof Zend_Db_Select) {
$md5 = md5($where->assemble());
} else {
$md5 = md5(var_export($this->showDeleted, true) . var_export($this->usePaginator, true) . var_export($where, true) . var_export($order, true) . var_export($count, true) . var_export($offset, true));
}
// Verifica se tem no cache
// o Zend_Paginator precisa do Zend_Paginator_Adapter_DbSelect para acessar o cache
if ($this->getUseCache() && !$this->getUsePaginator() && $this->getCache()->test($md5)) {
return $this->getCache()->load($md5);
} else {
// Define a consulta
if ($where instanceof Zend_Db_Select) {
$select = $where;
} else {
$select = $this->getSelect($where, $order, $count, $offset);
}
// Verifica se deve usar o Paginator
if ($this->getUsePaginator()) {
$fetchAll = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
// Verifica se deve usar o cache
if ($this->getUseCache()) {
$fetchAll->setCacheEnabled(true)->setCache($this->getCache());
}
// Configura o paginator
$fetchAll->setPageRange($this->getPaginator()->getPageRange());
$fetchAll->setCurrentPageNumber($this->getPaginator()->getCurrentPageNumber());
$fetchAll->setItemCountPerPage($this->getPaginator()->getItemCountPerPage());
} else {
// Recupera os registros do banco de dados
$fetchAll = $this->getTableGateway()->fetchAll($select);
// Verifica se foi localizado algum registro
if (!is_null($fetchAll) && count($fetchAll) > 0) {
// Passa o $fetch para array para poder incluir campos extras
$fetchAll = $fetchAll->toArray();
// Verifica se deve adiciopnar campos extras
$fetchAll = $this->getFetchAllExtraFields($fetchAll);
} else {
$fetchAll = null;
}
// Grava a consulta no cache
if ($this->getUseCache()) {
$this->getCache()->save($fetchAll, $md5);
}
}
// Some garbage collection
unset($select);
// retorna o resultado da consulta
return $fetchAll;
}
}