PHP code example of xiidea / easy-menu-acl-bundle
1. Go to this page and download the library: Download xiidea/easy-menu-acl-bundle library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
xiidea / easy-menu-acl-bundle example snippets
class MainMenuListener
{
/**
* @var TraceableEventDispatcher
*/
private $dispatcher;
public function __construct(TraceableEventDispatcher $dispatcher){
$this->dispatcher = $dispatcher;
}
/**
* @param EasyMenuEvent $event
*/
public function buildMainMenu(EasyMenuEvent $event)
{
$menu = $event->getMenu();
$factory = $event->getFactory();
$menu->addChild('Home', array('uri' => '/'));
$menu->addChild('Reports', array('route' => 'report_route'));
//..
}
/**
* @param EasyMenuEvent $event
*/
public function buildSideBarMenu(EasyMenuEvent $event)
{
$menu = $event->getMenu();
$factory = $event->getFactory();
$menu->addChild('Home Page', array('uri' => '/'));
$menu->addChild('Reports', array('route' => 'report_route'));
//..
}
}
//Menu builder
use Xiidea\EasyMenuAclBundle\Event\EasyMenuEvent;
class MenuBuilder extends ContainerAware
{
public function mainMenu(FactoryInterface $factory, array $options)
{
$menu = $factory->createItem('root');
$menu->addChild('Home', array('uri' => '/'));
$menu->addChild('Reports', array('route' => 'report_route'));
//.....
$this->container->get('event_dispatcher')->dispatch(
"xiidea.easy_menu_acl_post_build",
new EasyMenuEvent($factory, $menu)
);
return $menu;
}
//Menu builder
class MenuBuilder extends ContainerAware
{
public function mainMenu(FactoryInterface $factory, array $options)
{
$menu = $factory->createItem('root');
$menu->addChild('Home', array('uri' => '/'));
$menu->addChild('Reports', array('route' => 'report_route'));
//.....
$this->container->get('xiidea.easy_menu_acl.access_filter')->apply($menu);
return $menu;
}
bash
$ php composer.phar update xiidea/easy-menu-acl-bundle
php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Xiidea\EasyMenuAclBundle\XiideaEasyMenuAclBundle(),
);
}