注意:未定义的索引:translation_domain

时间:2017-11-11 15:01:45

标签: symfony undefined sonata-admin sonata undefined-index

我为我的英语道歉。

前段时间我在Symfony上开发项目时遇到了问题。问题出现在SonataAdminBundle。

The error looks like this

我的管理员课程

<?php

namespace Flatbel\FlatBundle\Admin;

use Flatbel\FlatBundle\Entity\User;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;

class AdminAdmin extends AbstractAdmin
{

    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper

            ->with('Основная информация', array('class' => 'col-md-8'))
                ->remove('userid')
                ->add('flattype', 'choice', array(
                    'choices'  => array(
                        'VIP' => 'VIP',
                        'Стандарт' => 'Стандарт',
                        'Бюджет' => 'Бюджет'
                    ),
                    'choices_as_values' => true, 'label' => 'Тип квартиры', 'placeholder'=>'Выбрать...'
                ))
                ->add('numberofbeds','choice', array(
                    'choices'  => array(
                        '1' => '1',
                        '2' => '2',
                        '3' => '3',
                        '4' => '4',
                        '5' => '5',
                        '6' => '6',
                        '6+' => '7',
                    ),
                    'choices_as_values' => true, 'label'=>'Количество спальных мест', 'placeholder'=>'Выбрать...'
                ))
                ->add('rooms','choice', array(
                    'choices'  => array(
                        '1' => '1',
                        '2' => '2',
                        '3' => '3',
                        '4+' => '4',
                    ),
                    'choices_as_values' => true, 'label'=>'Число комнат', 'placeholder'=>'Выбрать...'
                ))
                ->add('streettype', 'choice', array(
                    'choices' => array(
                        'Проспект' => 'Проспект',
                        'Улица'=>'Улица',
                        'Переулок'=>'Переулок'
                    ),
                    'choices_as_values' => true, 'label'=>'Тип', 'placeholder'=>'Выбрать...'
                ))
                ->add('street', 'text', array('label'=>'Название'))
                ->add('home',null,array('label'=>'Номер дома'))
                ->add('priceday',null,array('label'=>'Цена за день'))
                ->add('pricehour',null,array('label'=>'Цена за час'))
                ->add('pricenight',null,array('label'=>'Цена за ночь'))
                ->add('floorhome',null,array('label'=>'Число этажей в дома'))
                ->add('floor',null,array('label'=>'Этаж'))
                ->add('metro','choice', array(
                    'choices'  => array(
                        'Каменная горка'=>'Каменная горка',
                        'Кунцевщина'=>'Кунцевщина',
                    ),
                    'choices_as_values' => true, 'label'=>'Ближайшее метро', 'placeholder'=>'Выбрать...'
                ))

                ->add('telnumber',null,array('label'=>'Номер телефона'))
                ->add('about',null,array('label'=>'Описание'))
            ->end()

            ->with('Дополнительная информация',array('class'=>'col-md-4'))
                ->add('tv',null,array('label'=>'Телевизор'))
                ->add('wifi',null,array('label'=>'Wi-Fi'))
                ->add('parking',null,array('label'=>'Стоянка'))
                ->add('microwave',null,array('label'=>'Микроволновка'))
                ->add('washer',null,array('label'=>'Стиральная Машина'))
                ->add('bath',null,array('label'=>'Ванна'))
                ->add('shower',null,array('label'=>'Душ'))
                ->add('fridge',null,array('label'=>'Холодильник'))
                ->add('dishes',null,array('label'=>'Посуда'))
                ->add('linens',null,array('label'=>'Постельное бельё'))
                ->remove('payornot')
                ->remove('description')
            ->end()

            ->with('Фотографии',array('class'=>'col-md-8'))
                ->add('mainphoto', 'sonata_media_type', array(
                    'provider' => 'sonata.media.provider.image',
                    'context'  => 'flatphotos',
                ))
                ->add('photo1','sonata_media_type', array(
                    'provider' => 'sonata.media.provider.image',
                    'context'  => 'flatphotos',
                ))
                ->add('photo2','sonata_media_type', array(
                    'provider' => 'sonata.media.provider.image',
                    'context'  => 'flatphotos',
                ))
                ->add('photo3','sonata_media_type', array(
                    'provider' => 'sonata.media.provider.image',
                    'context'  => 'flatphotos',
                ))
            ->end()
        ;
    }

    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('id')
            ->addIdentifier('userid')
            ->addIdentifier('payornot')
            ->addIdentifier('flattype')
            ->addIdentifier('numberofbeds')
            ->addIdentifier('rooms')
            ->addIdentifier('street')
            ->addIdentifier('streettype')
            ->addIdentifier('home')
            ->addIdentifier('priceday')
            ->addIdentifier('pricehour')
            ->addIdentifier('pricenight')
            ->addIdentifier('floorhome')
            ->addIdentifier('floor')
            ->addIdentifier('tv')
            ->addIdentifier('wifi')
            ->addIdentifier('parking')
            ->addIdentifier('microwave')
            ->addIdentifier('washer')
            ->addIdentifier('bath')
            ->addIdentifier('shower')
            ->addIdentifier('fridge')
            ->addIdentifier('dishes')
            ->addIdentifier('linens')
           ;
    }

    public function toString($object)
    {
        return $object instanceof User
            ? $object->getUsername()
            : 'Flat'; // shown in the breadcrumb on the create view
    }

    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('id')
            ->add('userid')
            ->add('payornot')
            ->add('flattype')
            ->add('numberofbeds')
            ->add('rooms')
            ->add('street')
            ->add('streettype')
            ->add('home')
            ->add('priceday')
            ->add('pricehour')
            ->add('pricenight')
            ->add('floorhome')
            ->add('floor')
            ->add('tv')
            ->add('wifi')
            ->add('parking')
            ->add('microwave')
            ->add('washer')
            ->add('bath')
            ->add('shower')
            ->add('fridge')
            ->add('dishes')
            ->add('linens')
        ;
    }
}

我的 config.yml

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }
    - { resource: "@FlatbelFlatBundle/Resources/config/config.yml"}

parameters:
    locale: ru
    photo_directory: 'uploads/photos/'

framework:
    translator:      { fallbacks: ["%locale%"] }
    default_locale: ru
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    #serializer:      { enable_annotations: true }
    templating:
        engines: ['twig']
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        handler_id:  ~
    fragments:       ~
    http_method_override: true

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"

    form:
        resources:
            - 'FlatbelFlatBundle:Form:media_widgets.html.twig'

# Doctrine Configuration
doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset: UTF8
        options:
          1002: 'SET NAMES UTF8'
        types:
          json: Sonata\Doctrine\Types\JsonType


    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            ApplicationSonataMediaBundle: ~
            SonataMediaBundle: ~


# Swiftmailer Configuration
swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    spool:     { type: memory }

#FOSUserBundle Configuration
fos_user:
    db_driver: orm # other valid values are 'mongodb' and 'couchdb'
    firewall_name: main
    user_class: Flatbel\FlatBundle\Entity\User
    use_listener:           true
    use_flash_notifications: true
    use_authentication_listener: true
    use_username_form_type: true

    from_email:
        address: "%mailer_user%"
        sender_name: "%mailer_user%"
    profile:
        form:
            type:               fos_user_profile # or 'fos_user_profile' on Symfony < 2.8
            name:               fos_user_profile_form
            validation_groups:  [Profile, Default]
    change_password:
        form:
            type:               fos_user_change_password # or 'fos_user_change_password' on Symfony < 2.8
            name:               fos_user_change_password_form
            validation_groups:  [ChangePassword, Default]
    registration:
        confirmation:
            from_email: # Use this node only if you don't want the global email address for the confirmation email
                address:        registration@flatbel.by
                sender_name:    Registration
            enabled:    true # change to true for required email confirmation
            template:   '@FOSUser/Registration/email.txt.twig'
        form:
            type:               fos_user_registration # or 'fos_user_registration' on Symfony < 2.8
            name:               fos_user_registration_form
            validation_groups:  [Registration, Default]
    resetting:
        token_ttl: 86400
        email:
            from_email: # Use this node only if you don't want the global email address for the resetting email
                address:        resetting@flatbel.by
                sender_name:    Resetting
            template:   email/password_resetting.email.twig
        form:
            type:               fos_user_resetting # or 'fos_user_resetting' on Symfony < 2.8
            name:               fos_user_resetting_form
            validation_groups:  [ResetPassword, Default]
    service:
        mailer:                 fos_user.mailer.default
        email_canonicalizer:    fos_user.util.canonicalizer.default
        username_canonicalizer: fos_user.util.canonicalizer.default
        token_generator:        fos_user.util.token_generator.default
        user_manager:           fos_user.user_manager.default

#SonataAdminBundle
sonata_block:
    default_contexts: [cms]
    blocks:
        # enable the SonataAdminBundle block
        sonata.admin.block.admin_list:
            contexts: [admin]
        # ...
sonata_admin:
    security:
        handler: sonata.admin.security.handler.role


assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    bundles:        [FlatbelFlatBundle]

    filters:
        cssrewrite: ~
    assets:
        bootstrap_js:
            inputs:
                - "%kernel.root_dir%/../vendor/twitter/bootstrap/dist/js/bootstrap.js"
        bootstrap_css:
            inputs:
                - "%kernel.root_dir%/../vendor/twitter/bootstrap/dist/css/bootstrap.css"
                - "%kernel.root_dir%/../vendor/twitter/bootstrap/dist/css/bootstrap-theme.css"
            filters: [cssrewrite]

        bootstrap_glyphicons_ttf:
            inputs:
                - "%kernel.root_dir%/../vendor/twitter/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf"
            output: "fonts/glyphicons-halflings-regular.ttf"
        bootstrap_glyphicons_eot:
            inputs:
                - "%kernel.root_dir%/../vendor/twitter/bootstrap/dist/fonts/glyphicons-halflings-regular.eot"
            output: "fonts/glyphicons-halflings-regular.eot"
        bootstrap_glyphicons_svg:
            inputs:
                - "%kernel.root_dir%/../vendor/twitter/bootstrap/dist/fonts/glyphicons-halflings-regular.svg"
            output: "fonts/glyphicons-halflings-regular.svg"
        bootstrap_glyphicons_woff:
            inputs:
                - "%kernel.root_dir%/../vendor/twitter/bootstrap/dist/fonts/glyphicons-halflings-regular.woff"
            output: "fonts/glyphicons-halflings-regular.woff"

        jquery:
            inputs:
                - "%kernel.root_dir%/../vendor/components/jquery/jquery.js"

sonata_media:
    db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr it is mandatory to choose one here
    default_context: default # you need to set a context
    contexts:
        default:  # the default context is mandatory
            providers:
                - sonata.media.provider.dailymotion
                - sonata.media.provider.youtube
                - sonata.media.provider.image
                - sonata.media.provider.file
                - sonata.media.provider.vimeo

            formats:
                small: { width: 100 , quality: 70}
                big:   { width: 500 , quality: 70}
        flatphotos:
            providers:
                - sonata.media.provider.image

            formats:
                big:   { width: 500 , quality: 70}
    cdn:
        server:
            path: /uploads/media # http://media.sonata-project.org/

    filesystem:
        local:
            directory:  "%kernel.root_dir%/../web/uploads/media"
            create:     false

请帮帮我。我已经试图在第二周找到自己的错误,我一直在互联网上寻找类似的问题 - 我找不到任何东西。

修改

我的 services.yml

# Learn more about services, parameters and containers at
# http://symfony.com/doc/current/service_container.html
parameters:
#    parameter_name: value

services:
    FlatbelFlatFileUploader:
        class: Flatbel\FlatBundle\Service\FileUploader
        arguments:
            $targetDir: '%photo_directory%'

    admin.user:
        class: Flatbel\FlatBundle\Admin\UserAdmin
        arguments: [~, Flatbel\FlatBundle\Entity\User,~]
        tags:
            - { name: sonata.admin, manager_type: orm, label: User }
    admin.flat:
        class: Flatbel\FlatBundle\Admin\FlatAdmin
        arguments: [~, Flatbel\FlatBundle\Entity\Flat,~]
        tags:
            - { name: sonata.admin, manager_type: orm, label: Flat }

    admin.admin:
        class: Flatbel\FlatBundle\Admin\AdminAdmin
        arguments: [~, Flatbel\FlatBundle\Entity\Flat,~]
        tags:
            - { name: sonata.admin, manager_type: orm, label: Admin}

1 个答案:

答案 0 :(得分:2)

您的管理类扩展了AbstractAdmin,并且在其表单映射器中没有任何添加的字段。所以,你不需要这个:->remove('userid')。我尝试输入我的管理类同样的东西并得到“通知:未定义的索引:translation_domain”。