From 809d2dc24529dfac4253e886920ff1c4731e480d Mon Sep 17 00:00:00 2001 From: "maxime.steinhausser" Date: Tue, 19 May 2015 16:16:18 +0200 Subject: [PATCH 1/4] [Doc] Mention how to import routes when extending EasyAdminController --- .../tutorials/customizing-admin-controller.md | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Resources/doc/tutorials/customizing-admin-controller.md b/Resources/doc/tutorials/customizing-admin-controller.md index 50442b3062..f03603b6b4 100644 --- a/Resources/doc/tutorials/customizing-admin-controller.md +++ b/Resources/doc/tutorials/customizing-admin-controller.md @@ -70,6 +70,35 @@ This `indexAction()` method overrides the default `admin` route, which is essential to make your controller override the default `AdminController` behavior. +However, in order to activate this route, you need to import it and other routes defined in this controller through annotations by adding your controller as a resource in your routing files: +```yaml +# app/config/routing.yml + +app: + resource: @AppBundle/Controller/AdminController.php + type: annotation +``` + +At this point, you don't even need to import easyadmin routes from the original controller, and could simply replace the old definition: + +```yaml +# app/config/routing.yml + +# Old definition: +#easy_admin_bundle: +# resource: "@EasyAdminBundle/Controller/" +# type: annotation +# prefix: /admin + +# New +app_admin: + resource: "@AppBundle/Controller/AdminController.php" + type: annotation + prefix: /admin +``` + +and delete the `indexAction()` method in your controller (if you don't need to do anything within it). + Keep reading the practical examples of the next sections to learn which methods you can override in the backend. From 671b0e39e4d5539f0f66b838a7be2f303d2a2ca4 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 19 May 2015 17:30:55 +0200 Subject: [PATCH 2/4] Drastic simplification of the current explanations thanks to the trick suggested by @ogizanagi --- .../tutorials/customizing-admin-controller.md | 64 ++++--------------- 1 file changed, 11 insertions(+), 53 deletions(-) diff --git a/Resources/doc/tutorials/customizing-admin-controller.md b/Resources/doc/tutorials/customizing-admin-controller.md index f03603b6b4..1781ae8bb9 100644 --- a/Resources/doc/tutorials/customizing-admin-controller.md +++ b/Resources/doc/tutorials/customizing-admin-controller.md @@ -36,71 +36,29 @@ use JavierEguiluz\Bundle\EasyAdminBundle\Controller\AdminController as BaseAdmin class AdminController extends BaseAdminController { - // ... } ``` Extending from the default controller is not enough to override the entire -backend. That's why you must define an `indexAction()` method with the -following content: - -```php -// src/AppBundle/Controller/AdminController.php -namespace AppBundle\Controller; - -use Symfony\Component\HttpFoundation\Request; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; -use JavierEguiluz\Bundle\EasyAdminBundle\Controller\AdminController as BaseAdminController; - -class AdminController extends BaseAdminController -{ - /** - * @Route("/admin/", name="admin") - */ - public function indexAction(Request $request) - { - return parent::indexAction($request); - } - - // ... -} -``` +backend. You must also **update the routing configuration** to point the +`admin` route to the new controller. -This `indexAction()` method overrides the default `admin` route, which is -essential to make your controller override the default `AdminController` -behavior. +Open the `app/config/routing.yml` file and change the value of the `resource` +option defined by the existing `easy_admin_bundle` route to load your own +controller instead of the default one: -However, in order to activate this route, you need to import it and other routes defined in this controller through annotations by adding your controller as a resource in your routing files: ```yaml # app/config/routing.yml - -app: - resource: @AppBundle/Controller/AdminController.php - type: annotation -``` - -At this point, you don't even need to import easyadmin routes from the original controller, and could simply replace the old definition: - -```yaml -# app/config/routing.yml - -# Old definition: -#easy_admin_bundle: -# resource: "@EasyAdminBundle/Controller/" -# type: annotation -# prefix: /admin - -# New -app_admin: - resource: "@AppBundle/Controller/AdminController.php" +easy_admin_bundle: + # resource: "@EasyAdminBundle/Controller/" <-- REMOVE this line + resource: "@AppBundle/Controller/AdminController.php" # <-- ADD this line type: annotation prefix: /admin ``` -and delete the `indexAction()` method in your controller (if you don't need to do anything within it). - -Keep reading the practical examples of the next sections to learn which -methods you can override in the backend. +Save the changes and the backend will start using your own controller. Then, +keep reading the practical examples of the next sections to learn which +methods you can override in the controller. ### Customize the Instantiation of a Single Entity From 990d3389d8272982c121db6d31869096bdb7b7f7 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 19 May 2015 17:52:15 +0200 Subject: [PATCH 3/4] Added a note about the @Route defined by the index() method --- Resources/doc/tutorials/tips-and-tricks.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Resources/doc/tutorials/tips-and-tricks.md b/Resources/doc/tutorials/tips-and-tricks.md index 292e8ab4a8..c22836894a 100644 --- a/Resources/doc/tutorials/tips-and-tricks.md +++ b/Resources/doc/tutorials/tips-and-tricks.md @@ -77,6 +77,8 @@ use JavierEguiluz\Bundle\EasyAdminBundle\Controller\AdminController as BaseAdmin class AdminController extends BaseAdminController { /** + * Don't forget to add this route annotation! + * * @Route("/admin/", name="admin") */ public function indexAction(Request $request) @@ -95,6 +97,11 @@ class AdminController extends BaseAdminController } ``` +Beware that the `index()` method of the default `AdminController` defines the +`admin` route, which is used to generate every backend URL. This means that +when overriding the `index()` method in your own controller, you must also +redefine the `@Route()` annotation. Otherwise, the backend will stop working. + Create a Read-Only Backend -------------------------- From 5b85560fe1b0f4baa48fbc6f2c030cef3c291ee2 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 19 May 2015 17:58:17 +0200 Subject: [PATCH 4/4] Fixed a minor typo --- Resources/doc/tutorials/tips-and-tricks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/doc/tutorials/tips-and-tricks.md b/Resources/doc/tutorials/tips-and-tricks.md index c22836894a..52edfd2f08 100644 --- a/Resources/doc/tutorials/tips-and-tricks.md +++ b/Resources/doc/tutorials/tips-and-tricks.md @@ -79,7 +79,7 @@ class AdminController extends BaseAdminController /** * Don't forget to add this route annotation! * - * @Route("/admin/", name="admin") + * @Route("/", name="admin") */ public function indexAction(Request $request) {