【发布时间】:2016-03-08 16:42:10
【问题描述】:
要编写自定义 piwik 插件,我正在学习教程:http://piwik.org/blog/2014/09/create-widget-introducing-piwik-platform/
如何访问 piwik 在插件中收到的请求数据?
来自上述链接的示例小部件:
class Widgets extends \Piwik\Plugin\Widgets
{
/**
* Here you can define the category the widget belongs to. You can reuse any existing widget category or define your own category.
* @var string
*/
protected $category = 'ExampleCompany';
/**
* Here you can add one or multiple widgets. You can add a widget by calling the method "addWidget()" and pass the name of the widget as well as a method name that should be called to render the widget. The method can be defined either directly here in this widget class or in the controller in case you want to reuse the same action for instance in the menu etc.
*/
protected function init()
{
$this->addWidget('Example Widget Name', $method = 'myExampleWidget');
$this->addWidget('Example Widget 2', $method = 'myExampleWidget', $params = array('myparam' => 'myvalue'));
}
/**
* This method renders a widget as defined in "init()". It's on you how to generate the content of the widget. As long as you return a string everything is fine. You can use for instance a "Piwik\View" to render a twig template. In such a case don't forget to create a twig template (eg. myViewTemplate.twig) in the "templates" directory of your plugin.
*
* @return string
*/
public function myExampleWidget()
{
$view = new View('@MyWidgetPlugin/myViewTemplate');
return $view->render();
}
}
如何在插件中访问piwik为每个访问者请求接收的数据,例如请求头字段?
【问题讨论】: