Enable Cache plugin for ZFDebug
-
20-04-2021 - |
Question
I'm developing a web-site with Zend Framework and I wish to use ZFDebug.
I followed the installation instructions, described here, but I don't initialize Zend_Cache in the bootstrap (define cache manager settings in section of configuration file).
So, my bootstrap section for ZFDebug looks similar to this:
if ($this->hasPluginResource("cachemanager")) {
$this->bootstrap("cachemanager");
$cache = $this->getPluginResource("cachemanager")->getCacheManager()->getCache("default");
$options["plugins"]["Cache"] = array("backend" => $cache->getBackend());
}
$debug = new ZFDebug_Controller_Plugin_Debug($options);
With this code ZFDebug shows 'Cache' item in menu, but it is not clickable. What should I do to make ZFDebug show cache info? I use Xcache as Zend_Cache backend.
Solution
I only started playing with ZFDebug this morning but my Boostrap.php init's the cache and registers it first. In the _initZFDebug i call call the registry to get the cache.
protected function _initCache()
{
$frontendOptions = array(
'lifetime' => 3600*24*5, // cache lifetime of 5 days
'automatic_serialization' => true,
'logging' => false,
'caching' => true
);
$backendOptions = array(
'cache_dir' => './../data/cache/', // Directory where to put the cache files
'hashed_directory_level' => 2
);
$flickrFrontendOptions = array(
'lifetime' => 3600*24*5, // cache lifetime of 5 days
'automatic_serialization' => true,
'logging' => false,
'caching' => true
);
$flickrBackendOptions = array(
'cache_dir' => './../data/flickr/', // Directory where to put the cache files
'hashed_directory_level' => 2
);
// getting a Zend_Cache_Core object
$cache = Zend_Cache::factory(
'Core',
'File',
$frontendOptions,
$backendOptions);
Zend_Registry::set('cache', $cache);
$flickrcache = Zend_Cache::factory(
'Core',
'File',
$flickrFrontendOptions,
$flickrBackendOptions);
Zend_Registry::set('flickrcache', $flickrcache);
}
protected function _initZFDebug()
{
if ($this->hasOption('zfdebug'))
{
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('ZFDebug');
$options = array(
'plugins' => array('Variables',
'Database' => array('adapter' => $db),
'File' => array('basePath' => $this->hasOption('zfdebug.basePath')),
'Cache' => array('backend' => Zend_Registry::get('cache')->getBackend()),
'Exception')
);
$debug = new ZFDebug_Controller_Plugin_Debug($options);
$this->bootstrap('frontController');
$frontController = $this->getResource('frontController');
$frontController->registerPlugin($debug);
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow