如何将自定义调试数据添加到ZendDebugToolbar

时间:2014-05-06 05:31:37

标签: php zend-framework2

我正在使用ZendDebugToolbar,它在应用上显示正常,但是,如何向其发送自定义调试数据?例如,如果我想将一些关键会话信息转储给它或简单的var_dump?

2 个答案:

答案 0 :(得分:0)

我假设您指的是ZFDebug

由于ZFDebug作为仅在dispatchLoopShutdown()上触发的前端控制器插件运行,它实际上只能访问那里可用的变量,通常来自Zend_Registry,{等类的长寿单例实例{1}}(所以你可以获得请求和响应对象)等。内部进程(如模型和控制器)和ZFDebug插件之间没有直接通信的机制。

因此,对于您所询问的调试类型 - Zend_Controller_Front您自己的自定义变量和内省会话数据,可能是在系统的其他部分,如服务,控制器,模型等 - 它可能是最简单的只需将该数据添加到var_dump(),然后稍后在Zend_Registry标签下的ZFDebug中对其进行检查。

但是,如果您真的想在ZFDebug接口本身添加新内容,那么您可以使用自己的内部插件系统将标签/面板添加到其界面。

看起来你可以简单地创建一个实现接口Variableslink)的类,然后在bootstrap期间用主ZFDebug_Controller_Plugin_Debug_Plugin_Interface对象注册你的自定义插件。

这样的事情:

$debug

然后在/** * See some of the other plugin implementations for examples of what could go into each of * these methods. */ class My_ZFDebug_Controller_Plugin_SomePlugin implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface { /** * Has to return html code for the menu tab * * @return string */ public function getTab() { // @todo } /** * Has to return html code for the content panel * * @return string */ public function getPanel() { // @todo } /** * Has to return a unique identifier for the specific plugin * * @return string */ public function getIdentifier() { // @todo } /** * Return the path to an icon * * @return string */ public function getIconData() { // @todo } }

Bootstrap

像往常一样,您必须为命名空间protected function _initZFDebug() { $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace('ZFDebug'); $options = array( 'plugins' => array('Variables', 'Database' => array('adapter' => $db), 'File' => array('basePath' => '/path/to/project'), 'Cache' => array('backend' => $cache->getBackend()), 'Exception') ); $debug = new ZFDebug_Controller_Plugin_Debug($options); // register your custom sub-plugin $debug->registerPlugin(new My_ZFDebug_Controller_Plugin_SomePlugin()); $this->bootstrap('frontController'); $frontController = $this->getResource('frontController'); $frontController->registerPlugin($debug); } 或您用于自定义类的任何内容进行自动加载。

请记住,与之前相同的约束适用:插件可用的唯一数据是长期存在的实例,您可以静态地从以太中取出;像My_Zend_Registry(因此请求/响应)等等。

答案 1 :(得分:0)

@ vinygarcia87是正确的答案。 无法将其选为正确答案,因为您将其键入为注释。