English 中文(简体)
2. 采用可与书状2相联的理论
原标题:Using doctrine translatable together with Symfony 2 forms

我有实体,有2个可移植的领域,利用可转移的理论延伸:

class Page implements Translatable
{
    /......

    /**
     * @var string $name
     * @GedmoTranslatable
     * @ORMColumn(name="name", type="string", length=255)
     */
    private $name;

    /**
     * @var text $content
     * @GedmoTranslatable  
     * @ORMColumn(name="content", type="text")
     */
    private $content; 

 /........
}

I use one table for multiple entities translations. Now i would like to use one form to get the original and translated (to 1 language) values for these attributes, so it should have 4 fields.

I ve defined new form derivating from AbstractType and tried to add those 2 fields using FormBuilder, but it says that their corresponding entities do not contain these fields. I ve tried to add these fields to entities, and declare getters for them, but the only way i know to get translations for entities is to use dedicated entity manager and AFAIK providing entity manager access to entity isn t good practice.

是否有办法使用处理此类事情的形式?

问题回答

我知道这是一个老问题,但无论如何。

您可以把翻译内容的田地用表Builder来说明:

array (mapped =>false>

收集数据如下:

$form->get( field_name )->getData();

之后继续这样做。

https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/translatable.md#multi-translations”rel=“nofollow”>https://github.com/l3pp4rd/DoctrineExtens/blob/master/doc/translatable.md#multi-translations

我希望它有助于一些人。





相关问题
Zend and static class properties

I m trying to assign a value to a static class property when defining it: namespace Base; abstract class Skeleton { protected static $entityManager = end_Registry::get("EntityManager"); ......

require_once missing doctrine zend framework

I m integrating doctrine with Zend Framework. I ve hit an error thrown from cli. It seems Zend_Application_Bootstrap_Bootstrap does not have a require_once for ...

doctrine: QueryBuilder vs createQuery?

In Doctrine you can create DQL in 2 ways: EntityManager::createQuery: $query = $em->createQuery( SELECT u FROM MyProjectModelUser u WHERE u.id = ?1 ); QueryBuilder: $qb->add( select , u ) ...

热门标签