This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.
This package is abandoned and no longer maintained. No replacement package was suggested.

Toolbar handling for Symfony2 applications

Installs: 10

Dependents: 0

Suggesters: 0

Security: 0

Stars: 6

Watchers: 0

Forks: 0

Open Issues: 1


dev-master 2012-06-22 10:54 UTC

This package is not auto-updated.

Last update: 2020-01-24 14:59:54 UTC


This bundle provides simple toolbars for Symfony2 applications. The toolbars consist of buttons that may have icons, labels and accesskeys associated with them. The buttons may trigger GET or POST actions on URLs.

The toolbars have been designed to be quite similar to the toolbar concept in the MidCOM framework.

If you are looking for navigation menus instead of action-oriented toolbars, then KnpMenuBundle is a better option.


Install this bundle by adding the following to the deps file and running php bin/vendors install:


Then add the Midgard namespace to the app/autoload.php:

'Midgard' => __DIR__.'/../vendor'

And enable this bundle in your Kernel:

new Midgard\ToolbarBundle\MidgardToolbarBundle()


Toolbars can be used either directly, or through a toolbar provider. Direct toolbars are useful for situations where you want for example to add a toolbar to each item in a listing. Toolbars used via the toolbar provider can be used for shared toolbars on a web application where different parts of the application may register their own actions into the toolbar.

Direct toolbars

use Midgard\ToolbarBundle\Toolbar\Toolbar;

$toolbar = new Toolbar();

// GET action
        'url' => '/login',
        'label' => 'Log in',
        'icon' => '/web/some-icon.png',
        'helptext' => 'Log in to the system',

// POST action
        'url' => '/myformprocessor',
        'label' => 'Delete',
        'post' => true,
        'hiddenargs' => array(
            'article_id' => 1,

echo $toolbar->render();

In addition to providing direct URLs to the addItem method, you can also have the Symfony2 router generate them for you. In that case provide the URL in array format, for example:

        'url' => array(
            'route' => '_demo_hello',
            'parameters' => array(
                'name' => 'World',
        'label' => 'Say hello',

For URL generation to work, you need to pass the Dependency Injection container to the toolbar with the setContainer method. Centralized toolbars explained below do this step automatically.

Centralized toolbars

Centralized toolbars are accessible from the provider by name. You can have multiple. For example, the Midcom Compatibility Bundle uses four:

  • view: Toolbar associated with the main object of a page (actions like "edit")
  • node: Toolbar associated with the bundle that provides the current view (actions like "add")
  • host: Site-wide toolbar (actions like "logout")
  • help: Access to contextual help

Quick usage example:

$toolbar = $this->container->get('midgard.toolbar.provider')->get('main');

echo $this->container->get('midgard.toolbar.provider')->render('main');
// or echo $toolbar->render();