7

I tried to install sonata admin bundle to administrate my users.

I use FOS user bundle.

I have folowed the instructions, but anything went wrong and I don't find what.

I have the error:

Cannot automatically determine base route name, please define a default baseRouteName value for the admin class UserBundle\Admin\UserAdmin in C:\Users\Alexandre\hubiC\www\questionnaire\app/config. (which is being imported from "C:\Users\Alexandre\hubiC\www\questionnaire\app/config\routing.yml").

In my service I have:

services:
    sonata.admin.user:
        class: UserBundle\Admin\UserAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: "Content", label: "User" }
        arguments:
            - ~
            - UserBundle\Entity\User
            - ~
        calls:
            - [ setTranslationDomain, [UserBundle]]

In my config:

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }
    - { resource: @UserBundle/Resources/config/admin.yml }
sonata_block:
    default_contexts: [cms]
    blocks:
        # Enable the SonataAdminBundle block
        sonata.admin.block.admin_list:
            contexts:   [admin]
        # Your other blocks

And the file UserAdmin:

<?php // 
namespace UserBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;

class UserAdmin extends Admin
{
    // Fields to be shown on create/edit forms
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('nom')
            ->add('prenom')
            ->add('adresse')
            ->add('npa')
            ->add('localite')
            ->add('entreprise')
        ;
    }

    // Fields to be shown on filter forms
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('nom')
            ->add('prenom')
            ->add('adresse')
            ->add('npa')
            ->add('localite')
            ->add('entreprise')
        ;
    }

    // Fields to be shown on lists
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('nom')
            ->add('prenom')
            ->add('adresse')
            ->add('npa')
            ->add('localite')
            ->add('entreprise')
        ;
    }
}

This file in the folder UserBundle/Admin.

What was wrong?

Thanks

Juergen
  • 12,378
  • 7
  • 39
  • 55
anubis
  • 1,425
  • 5
  • 18
  • 47

1 Answers1

11

I'm not sure, why sonata doesn't automatically generate baseRouteName for you. I suppose that you define your custom directory structure or custom class name. You can dump return of getBaseRouteName method. This method is used to generate routing information.

You can also define it (not automatically).:

   protected $baseRouteName = 'your_name'; 
   protected $baseRoutePattern = 'your_name';

You can check routers in console by app/console router:debug, your new route from admin should be there

Routing problematic is described here in documentation: https://sonata-project.org/bundles/admin/2-3/doc/reference/routing.html

Fabian Kleiser
  • 2,988
  • 3
  • 27
  • 44
Piotr Galas
  • 4,518
  • 2
  • 21
  • 30
  • I have find the method in the admin.php file, but by what have I to change the value of the return? Or how to define the variables $baseRouteName? What's "your_name"? – anubis Jan 19 '15 at 09:41
  • 1
    your_name is custom string. You can type 'abc'. Normal way sonata define this string from your bundle name. – Piotr Galas Jan 19 '15 at 12:15
  • Ok, that works but now I access to dashboard and have my entities, but if I click on list, I haven't my entities, but I suppose that isn't related with the solution of my problem? – anubis Jan 19 '15 at 12:37
  • It's a known bug happening when you use an app bundle without vendor namespace: https://github.com/sonata-project/SonataAdminBundle/issues/2493. Apparently a fix has been made and is going to be published in Sonata 2.4. – konrad Mar 01 '15 at 10:13