【问题标题】:Sylius: How to extend Taxon model?Sylius:如何扩展分类模型?
【发布时间】:2018-01-16 08:48:08
【问题描述】:

我正在尝试通过添加新数据字段来扩展 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 的新手。

【问题讨论】:

    标签: php doctrine sylius


    【解决方案1】:

    你应该使用这个而不是 sylius_core 节点:

    sylius_taxonomy:
        resources:
            taxon:
                classes:
                    model: AppBundle\Entity\FooTaxon
    

    并且最好在实体属性名称中使用大写字母而不是蛇形大小写。

    【讨论】:

      猜你喜欢
      • 2012-06-26
      • 1970-01-01
      • 1970-01-01
      • 2014-06-20
      • 1970-01-01
      • 2016-09-27
      • 2013-11-10
      • 2018-05-11
      • 1970-01-01
      相关资源
      最近更新 更多