Segue o código abaixo o código do meu bootstrap.php
- Código: Selecionar tudo
protected function _initAutoload() {
$loader = new Zend_Loader_Autoloader_Resource(array(
'namespace' => 'RG',
'basePath' => APPLICATION_PATH,
'resourceTypes' => array(
'models' => array(
'namespace' => 'Model',
'path' => 'models/'
),
'plugins' => array(
'namespace' => 'Plugin',
'path' => 'library/Plugins/'
)
)
));
return $loader;
}
protected function _initRegistry() {
$path = APPLICATION_PATH . '/sites/'.MODULE.'/config.xml';
if (!file_exists($path)) {
throw new Exception('Não foi possível localizar o arquivo de configuração para o módulo.');
}
$config = new Zend_Config_Xml($path);
$this->config = $config;
Zend_Registry::set('config', $config);
}
protected function _initFrontController() {
$controller = Zend_Controller_Front::getInstance();
$controller->setControllerDirectory(APPLICATION_PATH ."/sites/". MODULE ."/controllers")
->setDefaultControllerName('home')
->registerPlugin(new RG_Plugin_Caching(array(
'frontend' => 'Output',
'backend' => 'File',
'frontendOptions' => array(
'lifetime' => 1200, // duração do cache, 20 minutos
'automatic_serialization' => true
),
'backendOptions' => array(
'cache_dir' => APPLICATION_PATH ."/sites/". MODULE ."/cache"
)
)));
return $controller;
}
protected function _initView() {
$view = new Zend_View();
$view->addHelperPath(APPLICATION_PATH .'/library/Helpers/');
$view->doctype('XHTML1_STRICT');
$view->setEncoding('ISO-8859-1');
$view->setEscape('htmlentities');
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
Zend_Layout::startMvc(array(
'layout' => 'layout',
'layoutPath' => APPLICATION_PATH ."/sites/". MODULE ."/view/scripts"
));
return $view;
}
Minha classe de Cache
- Código: Selecionar tudo
public function __construct($options) {
if ($options instanceof Zend_Config) {
$options = $options->toArray();
}
if (!is_array($options)) {
throw new Exception('Cache inválido');
}
if (array('frontend', 'backend', 'frontendOptions', 'backendOptions') != array_keys($options)) {
throw new Exception('Invalid cache options provided');
}
//$options['frontendOptions']['automatic_serialization'] = true;
$this->cache = Zend_Cache::factory(
$options['frontend'],
$options['backend'],
$options['frontendOptions'],
$options['backendOptions']
);
}
/**
* Start caching
*
* Determine if we have a cache hit. If so, return the response; else,
* start caching.
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) {
if (!$request->isGet() || ('development' === APPLICATION_ENV)) {
self::$doNotCache = true;
return;
}
$path = $request->getPathInfo();
$this->key = md5($path);
if (false !== ($response = $this->cache->load($this->key))) {
$response->sendResponse();
exit;
}
}
/**
* Store cache
*
* @return void
*/
public function dispatchLoopShutdown() {
if (self::$doNotCache
|| $this->getResponse()->isRedirect()
|| (null === $this->key)
) {
return;
}
$this->cache->save($this->getResponse(), $this->key);
}



