龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

将ZFDebug加入到ZF的项目中

时间:2014-07-22 14:51来源: 作者: 点击:
分享到:
创造ZFDebug的独立资源
创造ZFDebug的独立资源
<?php
/**
 * ZFDebug resource
 *
 * @copyright  Copyright (c) 2011 Ricky Feng (http://code.google.com/p/rphp4zf)
 * @license    New BSD License
 */

class RPHP_Application_Resource_ZFDebug extends Zend_Application_Resource_ResourceAbstract
{
	public function init()
	{
		//get ini file options
		$iniOptions = $this->getOptions();
		
		//set ZFDebug to autoload
		$autoloader = Zend_Loader_Autoloader::getInstance();
		$autoloader -> registerNamespace('ZFDebug');
		
		//initialized Front Controller
		$bootstrap = $this->getBootstrap();
		$bootstrap->bootstrap('frontController');
		$frontController = $bootstrap->getResource('frontController');

		if ($iniOptions['enabled'] && 'development' == APPLICATION_ENV) {
			//set ZFDebug options
			$options = array(
				'jquery_path' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js', 
				'plugins' => array(
					'Variables', 
					'File' => array('basePath' => APPLICATION_PATH .'/..'), 
					'Memory', 
					'Time', 
					'Registry',
					'Exception'
				),
			);

			//add cache option if specified
			if($bootstrap->hasPluginResource('cache')){
				$bootstrap->bootstrap('cache');
				$cache = $bootstrap->getPluginResource('cache')->getBackend();
	            $options['plugins']['Cache']['backend'] = $cache; 
			}
			
	        // add db option if specified
	        if ($bootstrap->hasPluginResource('db')) {
	            $bootstrap->bootstrap('db');
	            $db = $bootstrap->getPluginResource('db')->getDbAdapter();
	            $options['plugins']['Database']['adapter'] = $db;
	        }			
			
			$debug = new ZFDebug_Controller_Plugin_Debug($options);
			$frontController->registerPlugin($debug);
		}
	}

}

2. [代码][PHP]代码     跳至 [1] [2] [全屏预览]

在application.ini中加入

[development : production]
resources.zfdebug.enabled = 1
精彩图集

赞助商链接