Home >php教程 >PHP源码 >将ZFDebug加入到ZF的项目中

将ZFDebug加入到ZF的项目中

PHP中文网
PHP中文网Original
2016-05-25 17:12:351258browse

将ZFDebug加入到ZF的项目中

<?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(&#39;ZFDebug&#39;);
		
		//initialized Front Controller
		$bootstrap = $this->getBootstrap();
		$bootstrap->bootstrap(&#39;frontController&#39;);
		$frontController = $bootstrap->getResource(&#39;frontController&#39;);

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

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

}

2. [PHP]代码 

在application.ini中加入

[development : production]
resources.zfdebug.enabled = 1

 以上就是将ZFDebug加入到ZF的项目中的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn