gpt4 book ai didi

php - 未找到默认实体翻译的翻译形式

转载 作者:搜寻专家 更新时间:2023-10-31 21:07:22 25 4
gpt4 key购买 nike

我尝试设置翻译表单

http://a2lix.fr/bundles/translation-form/https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/translatable.md#translatable-entity-example

Composer .json

    "a2lix/translation-form-bundle": "2.*@dev",
"stof/doctrine-extensions-bundle": "1.2.*@dev",

配置.yml

stof_doctrine_extensions: 默认语言环境:en 订单: 默认: 可翻译:真实 懒惰:是的 懒惰:是的 时间戳:真

a2lix_translation_form:
locale_provider: default # [1]
locales: [pl, en, de] # [1-a]
default_locale: en
manager_registry: doctrine # [2]
templating: "A2lixTranslationFormBundle::default.html.twig"

实体

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use APY\DataGridBundle\Grid\Mapping as GRID;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Translatable;
use Symfony\Component\Validator\Constraints as Assert;

/**
* @ORM\Entity
* @ORM\Table(name="c_Base"
,indexes={
* @ORM\Index(name="search_name", columns={"name"}),
* @ORM\Index(name="orderCity", columns={"city"})
* })
*/
class Base implements Translatable{

/**
* @ORM\Column(type="bigint")
* @ORM\Id
*/
private $id;

/**
* Hexaid
* @var string
*/
private $hid;

/**
* @ORM\Column(type="string")
* @GRID\Column(title="name")
* @Gedmo\Translatable
* @var string
*/
private $name;

/**
* @Gedmo\Locale
* Used locale to override Translation listener`s locale
* this is not a mapped field of entity metadata, just a simple property
*/
private $locale;

构建表单

公共(public)函数 buildForm(FormBuilderInterface $builder, array $options) {

    $builder

->add('translations', 'a2lix_translations', array(
'fields'=>array(
'name'=>array(),
'description'=>array(
'field_type' => 'ckeditor'
)
)
)
);

错误

Neither the property "translations" nor one of the methods "getTranslations()", "translations()", "isTranslations()", "hasTranslations()", "__get()" exist and have public access in class "Mea\CharterBundle\Entity\Base".

我没有私有(private)的$translations; var in base - 因为是公共(public)翻译 - 例如个人翻译存在 $translations https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/translatable.md#personal-translations

但对于 https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/translatable.md#translatable-entity-example不是。

我可以在 http://a2lix.fr/bundles/translation-form/ 中使用它吗? ?

这是其他方式的例子 DoctrineExtensions Notice: Undefined index: foreignKey in $em->getRepository('Gedmo\\Translatable\\Entity\\Translation');

最佳答案

这是我当前项目中如何使用 KNP 的 DoctrineExtension 的工作示例(我知道这不能回答问题,请查看上面的评论)。

Composer .json:

"knplabs/doctrine-behaviors": "dev-master",
"a2lix/translation-form-bundle" : "dev-master"

配置文件:

imports:
...
- { resource: ../../vendor/knplabs/doctrine-behaviors/config/orm-services.yml }

framework:
translator:
fallback: "%locale%"
...

a2lix_translation_form:
locale_provider: default
locales: [ru, en]
default_locale: ru
required_locales: [ru]
manager_registry: doctrine
templating: "@SLCore/includes/translation.html.twig" # if you want to use your own template

实体:产品

use Knp\DoctrineBehaviors\Model\Translatable\Translatable;

class Product
{
use Translatable;

// other fields which should not be translated
// $translations field alredy has been created and mapped by DE

ProductTranslation(DE 需要此实体):

use Knp\DoctrineBehaviors\Model\Translatable\Translation;

class ProductTranslation
{
use Translation;

// fields that should be translated
// e.g. $title, $description (id, locale, translatable fields already have been created by Translation trait, mapped by DE)

ProductType 形式:

->add('translations', 'a2lix_translations', [/* other options go here */])

form.html.twig:

{% block javascripts %}
{{ parent() }}
<script type="text/javascript" src="{{ asset('bundles/a2lixtranslationform/js/a2lix_translation_bootstrap.js') }}"></script>
{% endblock %}

...

{{ form_widget(form.translations) }}

我知道这不是一个有趣的例子,但它确实有效。

关于php - 未找到默认实体翻译的翻译形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30272455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com