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


PHP Zend_Paginator::setCacheEnabled方法代码示例

本文整理汇总了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);
 }
开发者ID:rafalwrzeszcz,项目名称:zf2,代码行数:10,代码来源:PaginatorTest.php

示例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;
     }
 }
开发者ID:realejo,项目名称:library-zf1,代码行数:63,代码来源:Base.php


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