From 857c5f0f7d67a94f184286630405665fda0a9478 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Mon, 25 Oct 2010 19:32:51 +0800 Subject: [PATCH] Proofreading chapter 2 of the docs. --- .../doc/02-Integrate-With-Symfony.markdown | 81 +++++++++++-------- 1 file changed, 48 insertions(+), 33 deletions(-) diff --git a/Resources/doc/02-Integrate-With-Symfony.markdown b/Resources/doc/02-Integrate-With-Symfony.markdown index aa3f90b7..baedf10c 100644 --- a/Resources/doc/02-Integrate-With-Symfony.markdown +++ b/Resources/doc/02-Integrate-With-Symfony.markdown @@ -1,20 +1,23 @@ -Integrate menus with Symfony2 -========================== +Using menus with Symfony2 +========================= -Bundle\MenuBundle\Menu and Bundle\MenuBundle\MenuItem are perfectly decoupled from Symfony2. -They can be used in any PHP 5.3 project. +The core menu classes of the MenuBundle, `Bundle\MenuBundle\Menu` and +`Bundle\MenuBundle\MenuItem`, are perfectly decoupled from Symfony2 and +can be used in any PHP 5.3 project. -This bundle provides other classes that ease the integration of menus with a Symfony2 project. +This bundle also provides several classes that ease the integration of +menus within a Symfony2 project. ## Make your menu a service -There a lot of benefits making a menu a service. Its logic is then self-contained, and it can be accessed from any place of the project. +There a lot of benefits to making a menu a service. Its logic is then +self-contained,and it can be accessed from anywhere in the project. ### Create your menu class - // src/Bundle/MyBundle/Menu/MainMenu.php + // src/Application/MyBundle/Menu/MainMenu.php - Bundle\MyBundle\Menu\MainMenu + Application\MyBundle\Menu\MainMenu @@ -49,30 +55,39 @@ It requires a Symfony Router in order to generate uris. ... +If you include the menu configuration in your bundle (as shown above), you'll +need to include it as a resource in your base configuration: + + # app/config/config.xml + ... + + + ### Access the menu service - You can now access your menu like any Symfony service: +You can now access your menu like any Symfony service: - $menu = $container->get('menu.main'); + $menu = $container->get('menu.main'); - From a controller it's even easier: +From a controller, it's even easier: - $menu = $this['menu.main'] + $menu = $this['menu.main'] - The menu is loazy loaded, and will construct its children the first time you access it. +The menu is lazy loaded, and will construct its children the first time +you access it. ## Create a template helper for your menu You will probably need to access the menu from a template. -You may render a whole action to get the menu from a controller class, -pass it to a template and the render it. -But it would be a bit overkill. You can easily create a Symfony template helper instead. -This bundle provides a generic class for menu template helpers, all you need is -to declare the helper. +You _could_ render an entire action to get the menu from a controller class, +pass it to a template and the render it. But it would be a bit overkill. +You can easily create a Symfony template helper instead. This bundle +provides a generic class for menu template helpers, all you need to do is +declare the helper. ### Declare your menu template helper - # src/Bundle/MyBundle/Resources/config/menu.xml + # src/Application/MyBundle/Resources/config/menu.xml @@ -93,12 +108,12 @@ Or manipulate it: $view['main_menu']['Home']->setLabel('Home'); $view['main_menu']['Home']->setIsCurrent(true); - ## Customize your Menu -If you want to customize the way your menu are rendered, just create a custom MenuItem class +If you want to customize the way your menu are rendered, just create a +custom `MenuItem` class - # src/Bundle/MyBundle/Menu/MyCustomMenuItem.php + # src/Application/MyBundle/Menu/MyCustomMenuItem.php addChild('Home', $router->generate('homepage')); $this->addChild('Comments', $router->generate('comments')); } } -Or, if you want to customize each child item, pass them as an argument of the addChild method +Or, if you want to customize each child item, pass them as an argument of +the `addChild()` method: - // src/Bundle/MyBundle/Menu/MainMenu.php + // src/Application/MyBundle/Menu/MainMenu.php