PHP code example of wemakecustom / menu-part-bundle
1. Go to this page and download the library: Download wemakecustom/menu-part-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/ */
wemakecustom / menu-part-bundle example snippets
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new WMC\MenuPartBundle\WMCMenuPartBundle(),
);
}
// src/Acme/DemoBundle/Menu/UserMenu.php
namespace Acme\DemoBundle\Menu;
use WMC\MenuPartBundle\Menu\MenuPartInterface;
use JMS\DiExtraBundle\Annotation\Service;
use JMS\DiExtraBundle\Annotation\Tag;
use JMS\DiExtraBundle\Annotation\Inject;
use JMS\DiExtraBundle\Annotation\InjectParams;
use Knp\Menu\MenuItem;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
/**
* @Service(public=false)
* @Tag("wmc.menu_part", attributes={"menu" = "user"})
*/
class UserMenu implements MenuPartInterface
{
protected $authorizationChecker;
/**
* @InjectParams({
* "authorizationChecker" = @Inject("security.authorization_checker")
* })
*/
public function __construct(AuthorizationCheckerInterface $authorizationChecker)
{
$this->authorizationChecker = $authorizationChecker;
}
public function addMenuParts(MenuItem $menu)
{
if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
$menu->addChild('Profile', array('route' => 'fos_user_profile_show'));
}
}
}
// Assuming the L10n visitor is enabled for the current menu.
// Translated with trans, using no parameters and the default translation domain
$menu->addChild('home', ['route' => 'home']);
// Translated with trans, using the %username% parameter
// and the FOSUserBundle translation domain
$menu->addChild('account', [
'route' => 'my_account',
'extras' => [
'translation_parameters' => ['%username%' => $user],
'translation_domain' => 'FOSUserBundle',
]
]);
// Translated with transChoice
$menu->addChild('notifications', [
'route' => 'my_notifications',
'extras' => [
'translation_number' => $user->getNotifications()->count(),
]
]);
// Not translated
$menu->addChild(':)', [
'route' => 'happy',
'extras' => [
'translation_parameters' => false,
]
]);
bash
$ php composer.phar
twig
{{ knp_menu_render('user') }}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.