【问题标题】:How to add a phpcr-odm ReferenceMany field to sonata admin?如何将 phpcr-odm ReferenceMany 字段添加到奏鸣曲管理员?
【发布时间】:2014-07-07 19:56:04
【问题描述】:

在我的文档中,我有一个要存储相关节点的字段,我这样定义它:

/**
 * @PHPCRODM\ReferenceMany(targetDocument="Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page", strategy="hard")
*/
protected $related_guides;

我使用文档管理器添加了相关节点,我可以看到它们并在我的 twig 文件中创建了链接。我遇到的问题是允许管理员在奏鸣曲管理员中添加或删除相关节点。

当我使用 ORM 时,我使用了“sonata_type_collection”,但它似乎在 ODM 中不起作用。我收到了这个错误:

无效模式:s537a4d1c263c0_related_guides - 类型:sonata_type_collection - 映射:8

sonata_type_model_list 仅适用于 ReferenceOne 关系和 ReferenceMany 我收到此错误:

在链配置的命名空间 Doctrine\ODM\PHPCR\Document、Sandbox\MainBundle\Document、Vectorworks\Bundle\CmsBundle\Document、Symfony\Component\Routing 中找不到类“Doctrine\ODM\PHPCR\ReferenceManyCollection”, Symfony\Cmf\Bundle\RoutingBundle\Model, Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr, Symfony\Cmf\Bundle\MenuBundle\Model, Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr, Symfony\Cmf\Bundle\ ContentBundle\Model, Symfony\Cmf\Bundle\ContentBundle\Doctrine\Phpcr, Symfony\Cmf\Bundle\BlockBundle\Model, Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr, Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr, Symfony\Cmf\Bundle\SeoBundle\Model, Symfony\Cmf\Bundle\SeoBundle\Doctrine\Phpcr, Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr

有没有办法让 Sonata Admin 提供这个功能?顺便说一句,我的字段是 Doctrine\ODM\PHPCR\ReferenceManyCollection 的类型以支持 @ReferenceMany 关系。

【问题讨论】:

标签: symfony sonata-admin symfony-cmf


【解决方案1】:

上面的代码好像有点老了:对于 Symfony 3.3,使用下面的代码:

use Doctrine\Bundle\PHPCRBundle\Form\Type\DocumentType;
...
$formPapper->add('related_guides', DocumentType::class, 
        array(
            'choice_label' => 'title', // where TargetClass::getTitle()
            'class'    => 'Acme\DemoBundle\Document\TargetClass',
            'multiple' => true,
       ))
    ->end();

【讨论】:

    【解决方案2】:

    参考许多尝试使用“phpcr_document”:

    $formPapper->add('related_guides', 'phpcr_document', 
        array(
            'property' => 'title',
            'class'    => 'Acme\DemoBundle\Document\TargetClass',
            'multiple' => true,
       ))
    ->end();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-30
      • 1970-01-01
      • 2018-03-22
      • 1970-01-01
      • 2012-01-07
      • 1970-01-01
      相关资源
      最近更新 更多