Php 如何将自定义调试数据添加到工具栏

Php 如何将自定义调试数据添加到工具栏,php,zend-framework2,Php,Zend Framework2,我正在使用,它在应用程序上显示良好,但是,如何向其发送自定义调试数据?例如,如果我想将一些关键会话信息转储到它或一个简单的var_转储?我假设您指的是 由于ZFDebug作为前端控制器插件运行,只在dispatchLoopShutdown()上启动,因此它实际上只能访问那里可用的变量,通常是来自Zend_Registry,Zend_controller_front等类的长寿命单例实例(因此可以获取请求和响应对象),实际上,内部进程(如模型和控制器)与ZFDebug插件之间没有直接通信的机制 因此

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

我假设您指的是

由于ZFDebug作为前端控制器插件运行,只在
dispatchLoopShutdown()
上启动,因此它实际上只能访问那里可用的变量,通常是来自
Zend_Registry
Zend_controller_front
等类的长寿命单例实例(因此可以获取请求和响应对象),实际上,内部进程(如模型和控制器)与ZFDebug插件之间没有直接通信的机制

因此,对于您询问的调试类型-
var_dump()
您自己的自定义变量和自省会话数据,可能在系统的其他部分,如服务、控制器、模型,etc-最简单的方法可能是简单地将数据添加到
Zend_注册表
,然后稍后在ZFDebug中的
变量
选项卡下对其进行检查

但是,如果您真的想向ZFDebug接口本身添加新的内容,那么您可以使用其自己的内部插件系统向其接口添加选项卡/面板

看起来您可以简单地创建一个类来实现接口
ZFDebug\u Controller\u Plugin\u Debug\u Plugin\u 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
    }
}
然后在
引导中

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\ucode>或自定义类使用的任何内容设置自动加载


请记住,与以前相同的约束条件也适用:插件可用的唯一数据是可以静态地从以太网中拉出的长期实例;例如
Zend_注册表
Zend_控制器前端
(因此请求/响应)等。

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

感谢您详细的回复,但我不确定这是否有效,我指的是Zend Developer Tools工具栏,我在这里也使用ZF2而不是ZF1。。。不过,我会检查它,看看它是否工作相对类似。哦!好的,对不起。我已经添加了问题的链接并添加了zf2标记。看起来ZDT没有相同的插件结构。但它似乎有一个配置部分,您可以在其中指定“收集器”:也许这会有所帮助。请参阅我对这个问题的回答: