dev-master
9999999-devToolbar handling for Symfony2 applications
MIT
The Requires
- php >=5.3.2
- symfony/symfony 2.*
toolbar
Toolbar handling for Symfony2 applications
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., (*1)
The toolbars have been designed to be quite similar to the toolbar concept in the MidCOM framework., (*2)
If you are looking for navigation menus instead of action-oriented toolbars, then KnpMenuBundle is a better option., (*3)
Install this bundle by adding the following to the deps
file and running php bin/vendors install
:, (*4)
[MidgardToolbarBundle] git=git://github.com/bergie/MidgardToolbarBundle.git target=Midgard/ToolbarBundle
Then add the Midgard
namespace to the app/autoload.php
:, (*5)
'Midgard' => __DIR__.'/../vendor'
And enable this bundle in your Kernel:, (*6)
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., (*7)
use Midgard\ToolbarBundle\Toolbar\Toolbar; $toolbar = new Toolbar(); // GET action $toolbar->addItem( array( 'url' => '/login', 'label' => 'Log in', 'icon' => '/web/some-icon.png', 'helptext' => 'Log in to the system', ) ); // POST action $toolbar->addItem( array( '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:, (*8)
$toolbar->addItem( array( '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., (*9)
Centralized toolbars are accessible from the provider by name. You can have multiple. For example, the Midcom Compatibility Bundle uses four:, (*10)
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 helpQuick usage example:, (*11)
$toolbar = $this->container->get('midgard.toolbar.provider')->get('main'); $toolbar->addItem(...); echo $this->container->get('midgard.toolbar.provider')->render('main'); // or echo $toolbar->render();
Toolbar handling for Symfony2 applications
MIT
toolbar