无法确定属性“翻译"的访问类型在 Symfony 3.2.* 中,带有 Sonata 管理项目和 Sonata 翻译包 [英] Could not determine access type for property "translations" in Symfony 3.2.* with Sonata admin project and Sonata translation bundle

查看:23
本文介绍了无法确定属性“翻译"的访问类型在 Symfony 3.2.* 中,带有 Sonata 管理项目和 Sonata 翻译包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 Symfony 3.2.* 版本中安装了 Sonata 管理项目.我的项目中使用的 composer.json 文件中的组件如下:

I have installed Sonata admin project in Symfony 3.2.* version. Components that are being used in my project from composer.json file are as following:

composer.json 文件的包片段

composer.json file's package snippet

"require": {
        "php": ">=5.5.9",
        "ext-pdo_sqlite": "*",
        "a2lix/i18n-doctrine-bundle": "^0.1.0",
        "a2lix/translation-form-bundle": "^2.1",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/doctrine-cache-bundle": "^1.2",
        "doctrine/doctrine-fixtures-bundle": "^2.2",
        "doctrine/orm": "^2.5",
        "erusev/parsedown": "^1.5",
        "ezyang/htmlpurifier": "^4.7",
        "friendsofsymfony/user-bundle": "~2.0@dev",
        "incenteev/composer-parameter-handler": "^2.0",
        "sensio/distribution-bundle": "^5.0",
        "sensio/framework-extra-bundle": "^3.0.2",
        "sonata-project/admin-bundle": "^3.12",
        "sonata-project/doctrine-orm-admin-bundle": "^3.1",
        "sonata-project/translation-bundle": "^2.1",
        "stof/doctrine-extensions-bundle": "^1.2",
        "symfony/monolog-bundle": "^3.0",
        "symfony/polyfill-apcu": "^1.0",
        "symfony/property-access": "^3.2",
        "symfony/swiftmailer-bundle": "^2.3",
        "symfony/symfony": "^3.2",
        "twig/extensions": "^1.3",
        "twig/twig": "^1.28",
        "white-october/pagerfanta-bundle": "^1.0"
    },
    "require-dev": {
        "friendsofphp/php-cs-fixer"            : "^1.12",
        "phpunit/phpunit"                      : "^4.8 || ^5.0",
        "sensio/generator-bundle"              : "^3.0",
        "symfony/phpunit-bridge"               : "^3.0"
    },

详情

我正在使用翻译包.所以在我的表单中,对于每个字段,我都有两种语言的字段.表单完美呈现多语言选项.但是当我提交表单时,出现以下错误:

I am using translation bundle. So in my form, for each field I am having that fields for two languages. The form is rendering with multi-language options perfectly. But when I submits the form, I am getting below error:

无法确定属性translations"的访问类型.

Could not determine access type for property "translations".

vendor\symfony\symfony\src\Symfony\Component\PropertyAccess\PropertyAccessor.php 中第 649 行的堆栈跟踪

Stack Trace in vendor\symfony\symfony\src\Symfony\Component\PropertyAccess\PropertyAccessor.php at line 649

} elseif (self::ACCESS_TYPE_MAGIC === $access[self::ACCESS_TYPE]) {
        $object->{$access[self::ACCESS_NAME]}($value);
    } elseif (self::ACCESS_TYPE_NOT_FOUND === $access[self::ACCESS_TYPE]) {
        throw new NoSuchPropertyException(sprintf('Could not determine access type for property "%s".', $property));
    } else {
        throw new NoSuchPropertyException($access[self::ACCESS_NAME]);
    }

环境

奏鸣曲包

$ composer show sonata-project/*
sonata-project/admin-bundle              3.12.0 The missing Symfony Admin ...
sonata-project/block-bundle              3.3.0  Symfony SonataBlockBundle
sonata-project/cache                     1.0.7  Cache library
sonata-project/core-bundle               3.2.0  Symfony SonataCoreBundle
sonata-project/doctrine-orm-admin-bundle 3.1.3  Symfony Sonata / Integrate...
sonata-project/exporter                  1.7.0  Lightweight Exporter library
sonata-project/translation-bundle        2.1.0  SonataTranslationBundle

Symfony 软件包

Symfony packages

$ composer show symfony/*
symfony/monolog-bundle     3.0.1  Symfony MonologBundle
symfony/phpunit-bridge     v3.2.1 Symfony PHPUnit Bridge
symfony/polyfill-apcu      v1.3.0 Symfony polyfill backporting apcu_* func...
symfony/polyfill-intl-icu  v1.3.0 Symfony polyfill for intl's ICU-related ...
symfony/polyfill-mbstring  v1.3.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php56     v1.3.0 Symfony polyfill backporting some PHP 5....
symfony/polyfill-php70     v1.3.0 Symfony polyfill backporting some PHP 7....
symfony/polyfill-util      v1.3.0 Symfony utilities for portability of PHP...
symfony/security-acl       v3.0.0 Symfony Security Component - ACL (Access...
symfony/swiftmailer-bundle v2.4.2 Symfony SwiftmailerBundle
symfony/symfony            v3.2.2 The Symfony PHP framework

PHP 版本

$ php -v
# $ php -v
PHP 5.6.20 (cli) (built: Mar 31 2016 14:56:44)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

推荐答案

大多数情况下,当您忘记在实体类的构造函数中初始化集合时,会抛出此错误.

Most of the time this error gets thrown when you forget to initialize a collection in the constructor of your entity class.

看看你的实体类.您需要添加

Look at your entity class. You need to add

 $this->translations = new ArrayCollection();

到构造函数.

更一般地说,PropertyAccess 负责调用实体的 setter/getter,因此通常是与实体类相关的问题,而不是与表单类型相关的问题.

More generally, PropertyAccess is responsible for calling the setters/getters of your entity so usually it is a problem related to your entity class and not your form type.

这篇关于无法确定属性“翻译"的访问类型在 Symfony 3.2.* 中,带有 Sonata 管理项目和 Sonata 翻译包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆