我正在尝试通过添加新的数据字段来扩展Sylius\Component\Core\Model\Taxon。同样的过程在Sylius Core之外的另一个模型上也有效。运行doctrine:migrations:diff时,错误消息是“名为'sylius_dev.sylius_taxon‘的表已存在”。
对php bin/console debug:container --parameter=sylius.model.taxon.class的响应根本不会改变。
这是我在/src/AppBundle/Entity/FooTaxon.php中的新类
<?php
namespace AppBundle\Entity;
use Sylius\Component\Core\Model\Taxon as BaseTaxon;
class FooTaxon extends BaseTaxon
{
/**
* @var string
*/
private $field_one;
/**
* @return string
*/
public function getFieldOne(): string
{
return $this->field_one;
}
/**
* @param string $new_value
*/
public function setFieldOne(string $new_value): void
{
$this->field_one = $new_value;
}
/**
* @var int
*/
private $field_two;
/**
* @return int
*/
public function getFieldTwo(): int
{
return $this->field_two;
}
/**
* @param int $new_value
*/
public function setFieldTwo(int $new_value): void
{
$this->field_two = $new_value;
}
}这是我的/src/AppBundle/Resources/config/doctrine/FooTaxon.orm.yml
AppBundle\Entity\FooTaxon:
type: entity
table: sylius_taxon
fields:
field_one:
type: string
nullable: false
field_two:
type: integer
nullable: false下面是/app/config/config.yml中的新条目
sylius_core:
resources:
product_taxon:
classes:
model: AppBundle\Entity\FooTaxon感谢任何帮助,因为我对Symfony和Sylius都是新手。
发布于 2018-01-16 19:05:50
您应该使用此节点,而不是sylius_core节点:
sylius_taxonomy:
resources:
taxon:
classes:
model: AppBundle\Entity\FooTaxon最好在实体属性名称中使用upperCase,而不是snake_case。
https://stackoverflow.com/questions/48277207
复制相似问题