sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

Child admin and invalid links in the tab menu #2505

Closed rafrsr closed 9 years ago

rafrsr commented 10 years ago

I have one admin called "Merchant" and this has one child called "clerks". In the "Merchant" admin I use the method configureTabMenu in order to create a menu with the clerks. This works well, when I click in the "clerks" menu then the clerks admin is shown and this tab appear as active. All work fine in developer mode (debug=true) but in production the clerk menu does not appear as active and I see that the link has been changed like the following

admin/clerks/list?id=64

however in developer mode the links appear as

/admin/merchants/64/clerks/list

the last one should be the correct,

in the following file

Sonata\AdminBundle\Route\RoutesCache.php

when change the following line in the constructor all works fine

        $this->debug       = true;
djoo commented 9 years ago

Hi, i have the same problem. And i didn't find a solution :/ But for me the debug mode (true/false) change nothing.

djoo commented 9 years ago

Hi,

I find a temporary fix :

In this file : https://github.com/sonata-project/SonataAdminBundle/blob/master/Route/DefaultRouteGenerator.php

Comment l129

private function getCode(AdminInterface $admin, $name)
    {
        $this->loadCache($admin);
        if ($admin->isChild()) {
            return $admin->getBaseCodeRoute().'.'.$name;
        }
        // someone provide the fullname
        if (array_key_exists($name, $this->caches)) {
            //return $name; //Comment this line
        }
        // someone provide a code, so it is a child
        if (strpos($name, '.')) {
            return $admin->getCode().'|'.$name;
        }
        return $admin->getCode().'.'.$name;
    }
ste93cry commented 9 years ago

I have the same problem using Symfony 2.6 and SonataAdminBundle 2.3.1. Commenting that line doesn't fix the problem in my case. @rande can you have a look at this issue? It seems pretty important

manuelj555 commented 9 years ago

Related to #2147

sergiostrampelli commented 9 years ago

I have this problem and is related to route cache generated before the menu tab. To reproduce this issue you must have the parent admin that show links to the child admin. These links cause the generation of routes to the children like:

"bundle.admin.childthing.show" , "bundle.admin.childthing.edit" , "bundle.admin.childthing.list" etc.

Then, when I try to add the link, the default router generator find:

"bundle.admin.childthing.list"

instead of

"bundle.admin.parentthing.show|bundle.admin.childthing.list"

Pull request follow.

greg0ire commented 8 years ago

I had the same problem and worked around it by moving the child service definition before the parent service definition.

alfredoalfa commented 7 years ago

hi, i have the same problem. i will add the code.

error An exception has been thrown during the rendering of a template ("unable to find the route intranet.pni.oeu.admin.areaconocimiento|intranet.pni.oeu.admin.subareaConocimiento.list").

admin. $menu->addChild( 'Pagos', $admin->generateMenuUrl('intranet.pni.oeu.admin.subareaConocimiento.list', array('id' => $id)) ); }

sservice.yml

intranet.pni.oeu.admin.subareaConocimiento: class: Intranet\Pni\OeuBundle\Admin\SubAreaConocimientoAdmin arguments: [~, Intranet\Pni\OeuBundle\Entity\SubAreaConocimiento, ~] tags: