1

这个问题与PHP Debug Bar相关。

我正在向DataCollectorPHP 调试栏添加自定义。当我将鼠标悬停在它上面时,我想向它添加一些格式良好的信息。例如,

public function getWidgets() {
    $name = $this->getName();
    $hg_changeset = rtrim(`/usr/local/bin/hg id -i`,"\n+") ?: '(unavailable)';
    $hg_branch = rtrim(`/usr/local/bin/hg id -b`,"\n") ?: '(unavailable)';
    return array(
        $name => array(
            "icon" => "leaf",
            "tooltip" => "Changeset: $hg_changeset\nBranch: $hg_branch",
            "map" => $name,
            "default" => json_encode("Unknown"),
        )
    );
}

像这样渲染:

在此处输入图像描述

有没有办法可以将 HTML 放入tooltip?它似乎自动转义它。

4

1 回答 1

0

原来你可以像这样创建自己的指标,

var LinkIndicator = PhpDebugBar.DebugBar.Indicator.extend({

    tagName: 'a',

    render: function() {
        LinkIndicator.__super__.render.apply(this);
        this.bindAttr('href', function(href) {
            this.$el.attr('href', href);
        });
    }

});

您可以将其放入自己的文件中,并使用DebugBar\DataCollector\AssetProvider接口将其包含在您的收集器中。我在黑暗中刺了一下,该getWidgets方法有一个秘密属性,可让您指定自定义指标:

public function getWidgets()
{
    return array(
        "nameOfMyWidget" => array(
            "icon" => "inbox",
            "indicator" => "LinkIndicator", // lets you specify the JS "class" you just created
            "map" => "nameOfMyWidget",
            "default" => "'xxx'"
        )
    );
}

更新:所以这实际上并不是一个秘密,它隐藏在本页底部的文档中。

于 2014-05-10T00:19:14.403 回答