【问题标题】:OroPlatform: add file relation to an entityOroPlatform:向实体添加文件关系
【发布时间】:2021-09-21 21:16:51
【问题描述】:

上下文

我目前正在尝试将文件关系添加到我的 OroPlatform 项目的实体。 目标是让用户有机会在特定实体的创建/更新视图上上传文件。

我在 OroPlatform 文档中阅读了我必须创建一个新的迁移:https://doc.oroinc.com/master/backend/bundles/platform/AttachmentBundle/attachment-bundle-config/#attachment-bundle-file-types

这是我创建的迁移:

<?php

namespace Baltimore\Bundle\AppBundle\Migrations\Schema\v1_1_1;

use Doctrine\DBAL\Schema\Schema;

use Oro\Bundle\AttachmentBundle\Migration\Extension\AttachmentExtension;
use Oro\Bundle\AttachmentBundle\Migration\Extension\AttachmentExtensionAwareInterface;
use Oro\Bundle\MigrationBundle\Migration\Migration;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;

class AddAttachmentToBusinessUnit implements Migration, AttachmentExtensionAwareInterface
{
    /** @var AttachmentExtension */
    protected $attachmentExtension;

    /**
     * {@inheritdoc}
     */
    public function setAttachmentExtension(AttachmentExtension $attachmentExtension)
    {
        $this->attachmentExtension = $attachmentExtension;
    }

    /**
     * {@inheritdoc}
     */
    public function up(Schema $schema, QueryBag $queries)
    {
        $this->attachmentExtension->addFileRelation(
            $schema,
            'oro_business_unit',
            'document',
            [],
            15
        );
    }
}

我已将此行添加到我的实体的update.html.twigform_row(form.document)

问题

当我尝试访问更新页面时,出现以下错误:

"Neither the property "document" nor one of the methods "document()", "getdocument()"/"isdocument()"/"hasdocument()" or "__call()" exist and have public access in class "Symfony\Component\Form\FormView"."

我已经预热缓存以便为我的类生成访问器,并且方法getDocument()存在于生成的文件EX_OroOrganizationBundle_BusinessUnit.php

另外,该属性似乎已成功添加到我的实体中:

【问题讨论】:

    标签: orocrm orocommerce


    【解决方案1】:

    要添加新的表单字段,首先,您必须在表单类型扩展中定义它,然后您就可以从模板中访问它。

    How to Create a Form Type Extension

    【讨论】:

    【解决方案2】:

    终于我的需求发生了变化,但我想我有解决这个问题的答案。
    这是我要做的:

    /**
    * {@inheritdoc}
    */
    public function up(Schema $schema, QueryBag $queries)
    {
       $this->attachmentExtension->addFileRelation(
          $schema,
          'oro_business_unit',
          'document',
          [
             'extend' => [
                 'owner' => ExtendScope::OWNER_CUSTOM,
                 'is_extend' => true
              ],
              'entity' => ['label'=>'oro.organization.businessunit.entity_label'],
          ],
          15
       );
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-18
      • 1970-01-01
      • 2018-06-08
      • 2015-06-17
      • 1970-01-01
      • 2015-06-04
      • 2018-06-17
      相关资源
      最近更新 更多