Sonata admin bundle symfony

I tried installing the sonata admin package to administer my users.

I use the FOS package.

I described the instructions, but everything went wrong, and I did not find that.

I have an error:

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

In my service, I:

 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 configuration:

 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 UserAdmin file:

 <?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 is located in the UserBundle / Admin folder.

What happened?

thanks

+6
source share
1 answer

I'm not sure why sonata does not automatically generate baseRouteName for you. I believe that you are defining your own directory structure or custom class name. You can return the getBaseRouteName method. This method is used to generate routing information.

You can also detect it (not automatically) .:

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

You can check the routers on the console using the app / console: debug router, your new route from the administrator should be there

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

+9
source

Source: https://habr.com/ru/post/981188/


All Articles