简体   繁体   English

奏鸣曲管理员捆绑symfony

[英]sonata admin bundle symfony

I tried to install sonata admin bundle to administrate my users. 我试图安装sonata admin bundle来管理我的用户。

I use FOS user bundle. 我使用FOS用户包。

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. 无法自动确定基本路由名称,请在C:\\ Users \\ Alexandre \\ hubiC \\ www \\ questionnaire \\ app / config中为管理类UserBundle\\Admin\\UserAdmin定义默认的baseRouteName值。 (which is being imported from "C:\\Users\\Alexandre\\hubiC\\www\\questionnaire\\app/config\\routing.yml"). (从“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: 和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. 此文件位于UserBundle / Admin文件夹中。

What was wrong? 什么问题?

Thanks 谢谢

I'm not sure, why sonata doesn't automatically generate baseRouteName for you. 我不确定,为什么sonata不会自动为你生成baseRouteName。 I suppose that you define your custom directory structure or custom class name. 我想你定义了自定义目录结构或自定义类名。 You can dump return of getBaseRouteName method. 您可以转储getBaseRouteName方法的返回。 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 您可以通过app / console路由器检查控制台中的路由器:debug,来自admin的新路由应该在那里

Routing problematic is described here in documentation: https://sonata-project.org/bundles/admin/2-3/doc/reference/routing.html 文档中描述了路由问题: https//sonata-project.org/bundles/admin/2-3/doc/reference/routing.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM