2017 © Pedro Peláez

symfony-bundle dashboard-bundle

Dashboard bundle, widgets



Dashboard bundle, widgets

  • Sunday, July 31, 2016
  • by tkuska
  • Repository
  • 1 Watchers
  • 3 Stars
  • 80 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 2 Open issues
  • 1 Versions
  • 1 % Grown


This bundle provides a dashboard with customizable widgets., (*1)


composer require 2lenet/dashboard-bundle, (*2)

Setting up the bundle

Add this to services.yaml, (*3)

        resource: '../src/Widgets'
        tags: ['tkuska_dashboard.widget']

Add this to routes.yaml, (*4)

    resource: "@TkuskaDashboardBundle/Resources/config/routes.yaml"

You also need to update your database to have widget table., (*5)

php bin/console make:migration
php bin/console doc:mi:mi

Making widgets

All your widget classes will lie in src/Widgets/., (*6)

They must extend AbstractWidget., (*7)

use Tkuska\DashboardBundle\Widgets\AbstractWidget;

Existing methods that can be overriden: - __construct: the constructor for usual services injection. You need at least a Twig_Environment ($twig) - getName: must return general name of the widget - getJsonSchema: must return an array (that will be json encoded) that represents an Json Schema, for the widget configuration. (see also https://github.com/json-editor/json-editor) - getConfigForm: makes the configuration form. You shouldn't need to modify it, but it can happen in some cases (ex: bootstrap version) - support: returns true if widget is supported. If not, user won't be able to add such widget nor render it - supportsAjax: returns true if widget should be loaded asynchronously. If not, it will be loaded directly with the dashboard - transformResponse: takes Response representing the widget as argument and returns response. By default, it caches widgets for 300 seconds., (*8)

You must implement the render() method., (*9)

This method returns simple HTML. You can use $twig->render("template.html.twig", array(...)). Your templates should extend the base widget template, because it has some interactions. Otherwise, make sure you implement those interactions., (*10)

{% extends '@TkuskaDashboard/widget/base_widget.html.twig' %}

Note that base template uses Bootstrap panels, which means it is better to put your widget body in a <div class="panel-body">., (*11)

If you use the widget configuration (getJsonSchema) you must pass the form to the template with getConfigForm as 'form'., (*12)

This method renders the widget that is shown. All your logic should be in there., (*13)


by default the cache is enable, you can change timeout and key with, (*14)

public function getCacheKey():string{
    return $this->getId() . "_".md5($this->config);

public function getCacheTimeout():int {
    return 300;

above you see the default return., (*15)

If you want disable the cache for a widget getCacheTimeout have to return 0., (*16)

The Versions

31/07 2016



Dashboard bundle, widgets

  Sources   Download


The Requires

  • php >=5.3.2


by Tomasz Kuśka