Skip to content

Commit

Permalink
minor #318 Simplified the instructions to override the AdminControlle…
Browse files Browse the repository at this point in the history
…r (ogizanagi, javiereguiluz)

This PR was merged into the master branch.

Discussion
----------

Simplified the instructions to override the AdminController

Thanks to the trick suggested by @ogizanagi in #317 we can drastically simplify overriding instructions. Believe it or not, this is something that I was seeking since day one but I didn't know how to do it. Adding the empty `index` method looked very ugly to me, but I couldn't come up with the elegant solution provided by @ogizanagi. You won't believe how much I thank you for this suggestion!!!

Commits
-------

5b85560 Fixed a minor typo
990d338 Added a note about the @route defined by the index() method
671b0e3 Drastic simplification of the current explanations thanks to the trick suggested by @ogizanagi
809d2dc [Doc] Mention how to import routes when extending EasyAdminController
  • Loading branch information
javiereguiluz committed May 19, 2015
2 parents af29c8f + 5b85560 commit 91dbb69
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 31 deletions.
47 changes: 17 additions & 30 deletions Resources/doc/tutorials/customizing-admin-controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +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.

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:

```yaml
# app/config/routing.yml
easy_admin_bundle:
# resource: "@EasyAdminBundle/Controller/" <-- REMOVE this line
resource: "@AppBundle/Controller/AdminController.php" # <-- ADD this line
type: annotation
prefix: /admin
```
This `indexAction()` method overrides the default `admin` route, which is
essential to make your controller override the default `AdminController`
behavior.

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
Expand Down
9 changes: 8 additions & 1 deletion Resources/doc/tutorials/tips-and-tricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ use JavierEguiluz\Bundle\EasyAdminBundle\Controller\AdminController as BaseAdmin
class AdminController extends BaseAdminController
{
/**
* @Route("/admin/", name="admin")
* Don't forget to add this route annotation!
*
* @Route("/", name="admin")
*/
public function indexAction(Request $request)
{
Expand All @@ -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
--------------------------

Expand Down

0 comments on commit 91dbb69

Please sign in to comment.