Easyadminbundle: Unable to override AdminController to add custom entity action

Created on 13 Nov 2016  路  6Comments  路  Source: EasyCorp/EasyAdminBundle

Easyadmin 1.15.3, Symfony 2.8.7.

Any changes done to config.yml result on EasyAdmin's routing to become unavailable, on the dev environment.

routing.yml :

easy_admin_bundle:
    resource: "@AppBundle/Controller/Admin/AdminController.php"
    type:     annotation
    prefix:   /backend

I added custom action to my entity i overrided Adon controller :

Config.yml:

Utilisateurs :
        class: WebBundle\Entity\Utilisateurs
        list:
            actions: 
                - new
                - edit
                - { name: 'affectation', label : 'Affectation' }

BackendBundle/Admin/AdminController.php :

<?php

namespace BackendBundle\Controller\Admin;

use JavierEguiluz\Bundle\EasyAdminBundle\Controller\AdminController as BaseController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;

class AdminController extends BaseController {

    public function affectationAction(Request $request) {
        die('OKKKK');
    }

}

I got error : No route found for "GET /backend" 404 Not Found - NotFoundHttpException 1 linked Exception: ResourceNotFoundException 禄

Most helpful comment

@haithem-rihane I think that the problem is the following:

  1. You updated the YAML config as explained in the docs:
easy_admin_bundle:
    resource: "@AppBundle/Controller/Admin/AdminController.php"
    type:     annotation
    prefix:   /backend
  1. Your custom admin controller is not located in @AppBundle but in @BackendBundle.

So you should use instead the following config:

easy_admin_bundle:
    resource: "@BackendBundle/Controller/Admin/AdminController.php"
    type:     annotation
    prefix:   /backend

All 6 comments

You may have missed to redefine the indexAction with the proper routing annotation:

    /**
     * @Route("/", name="easyadmin")
     */
    public function indexAction(Request $request)
    {
        return parent::indexAction($request);
    }

The indexAction() method is the only "real controller" because it's the only method associated with a route (all the pages created with EasyAdmin use a single route called easyadmin). It makes some checks and then it redirects to the actual executed method, such as listAction(), showAction(), etc.:

see:

It Work ;) i added indexAction and i correct route Annotation to /backend

Thx A lot

i correct route Annotation to /backend

You should not have to, as you've already prefixed it in your routing config:

easy_admin_bundle:
    resource: "@AppBundle/Controller/Admin/AdminController.php"
    type:     annotation
    prefix:   /backend

It didn't work when i just added the indexAction so i changed the route annotation :

     /**
     * @Route("/backend", name="easyadmin")
     */
    public function indexAction(Request $request) {
        return parent::indexAction($request);
    }

@haithem-rihane I think that the problem is the following:

  1. You updated the YAML config as explained in the docs:
easy_admin_bundle:
    resource: "@AppBundle/Controller/Admin/AdminController.php"
    type:     annotation
    prefix:   /backend
  1. Your custom admin controller is not located in @AppBundle but in @BackendBundle.

So you should use instead the following config:

easy_admin_bundle:
    resource: "@BackendBundle/Controller/Admin/AdminController.php"
    type:     annotation
    prefix:   /backend

I had face same problem. Now it is solved. You can see my solution

http://toihid.com/?p=316

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joazvsoares picture joazvsoares  路  4Comments

devkbsc picture devkbsc  路  3Comments

haithem-rihane picture haithem-rihane  路  4Comments

Ealenn picture Ealenn  路  3Comments

javiereguiluz picture javiereguiluz  路  4Comments