OroPlatform:将文件关系添加到实体
OroPlatform: add file relation to an entity
上下文
我目前正在尝试将文件关系添加到我的 OroPlatform 项目的实体。
目标是让用户有机会在特定实体的 create/update 视图上上传文件。
我在 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.twig
中:form_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"."
我已经预热缓存以便为我的 class 生成访问器,生成的文件 EX_OroOrganizationBundle_BusinessUnit.php
中存在方法 getDocument()
此外,属性 似乎已成功添加到我的实体中:
要添加新的表单域,首先,您必须在表单类型扩展中定义它,然后您就可以从模板中访问它。
终于我的需求变了,但我想我已经有了解决这个问题的答案。
这是我要做的:
/**
* {@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
);
}
上下文
我目前正在尝试将文件关系添加到我的 OroPlatform 项目的实体。 目标是让用户有机会在特定实体的 create/update 视图上上传文件。
我在 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.twig
中:form_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"."
我已经预热缓存以便为我的 class 生成访问器,生成的文件 EX_OroOrganizationBundle_BusinessUnit.php
getDocument()
此外,属性 似乎已成功添加到我的实体中:
要添加新的表单域,首先,您必须在表单类型扩展中定义它,然后您就可以从模板中访问它。
终于我的需求变了,但我想我已经有了解决这个问题的答案。
这是我要做的:
/**
* {@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
);
}