[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 /* 4 * This file is part of the symfony package. 5 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file that was distributed with this source code. 9 */ 10 11 /** 12 * CacheHelper. 13 * 14 * @package symfony 15 * @subpackage helper 16 * @author Fabien Potencier <fabien.potencier@symfony-project.com> 17 * @version SVN: $Id: CacheHelper.php 2459 2006-10-20 08:15:03Z fabien $ 18 */ 19 20 /* Usage 21 22 <?php if (!cache('name')): ?> 23 24 ... HTML ... 25 26 <?php cache_save() ?> 27 <?php endif; ?> 28 29 */ 30 function cache($name, $lifeTime = 86400) 31 { 32 $context = sfContext::getInstance(); 33 34 if (!sfConfig::get('sf_cache')) 35 { 36 return null; 37 } 38 39 $request = $context->getRequest(); 40 $cache = $context->getViewCacheManager(); 41 42 if ($request->getAttribute('cache_started') !== null) 43 { 44 throw new sfCacheException('Cache already started'); 45 } 46 47 $data = $cache->start($name, $lifeTime); 48 49 if ($data === null) 50 { 51 $request->setAttribute('started', 1, 'symfony/action/sfAction/cache'); 52 $request->setAttribute('current_name', $name, 'symfony/action/sfAction/cache'); 53 54 return 0; 55 } 56 else 57 { 58 echo $data; 59 60 return 1; 61 } 62 } 63 64 function cache_save() 65 { 66 $context = sfContext::getInstance(); 67 68 if (!sfConfig::get('sf_cache')) 69 { 70 return null; 71 } 72 73 $request = $context->getRequest(); 74 75 if ($request->getAttribute('started', null, 'symfony/action/sfAction/cache') === null) 76 { 77 throw new sfCacheException('Cache not started'); 78 } 79 80 $name = $request->getAttribute('current_name', '', 'symfony/action/sfAction/cache'); 81 82 $data = $context->getViewCacheManager()->stop($name); 83 84 $request->setAttribute('started', null, 'symfony/action/sfAction/cache'); 85 $request->setAttribute('current_name', null, 'symfony/action/sfAction/cache'); 86 87 echo $data; 88 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |