为ZFDebug启用缓存插件

时间:2011-12-29 15:56:29

标签: zend-framework zend-cache

我正在使用Zend Framework开发一个网站,我希望使用ZFDebug 我按照安装说明进行了描述,描述了here,但是我没有在引导程序中初始化Zend_Cache(在配置文件的部分中定义缓存管理器设置)。
所以,我对ZFDebug的引导部分看起来类似于:

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);

使用此代码,ZFDebug在菜单中显示“缓存”项,但不可点击。我该怎么做才能让ZFDebug显示缓存信息?我使用Xcache作为Zend_Cache后端。

1 个答案:

答案 0 :(得分:0)

我今天早上才开始玩ZFDebug但是我的Boostrap.php init是缓存并首先注册它。在_initZFDebug中,我调用调用注册表来获取缓存。

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);
    }
}
相关问题