【问题标题】:Sylius customizing model dose not workingSylius 自定义模型不起作用
【发布时间】:2018-11-19 07:36:36
【问题描述】:

这是我的类文件 Country.php

<?php

namespace App\Entity;

use Sylius\Component\Addressing\Model\Country as BaseCountry;

class Country extends BaseCountry {

/**
 * @var bool
 */
private $flag;

/**
 * @return bool|null
 */
public function getFlag(): ?bool {
    return $this->flag;
}

/**
 * @param bool $flag
 */
public function setFlag(bool $flag): void {
    $this->flag = $flag;
   }

}

这是我的 orm 文件。 AppBundle/Resources/config/doctrine/Country.orm.yml

App\Entity\Country:
   type: entity
   table: sylius_country
   fields:
       flag:
           type: boolean
           nullable: true

这是我的配置文件。 config/_sylius.yml

sylius_addressing:
   resources:
       country:
           classes:
               model: App\Entity\Country

这一切都像 sylius 自定义模型一样好,但它不起作用。

【问题讨论】:

  • 您使用哪个版本的 Sylius?请更明确。究竟什么是“不工作”?
  • 我使用的是 sylius 1.3 版本。?扩展的 sylius 自定义模型不起作用。

标签: php frameworks symfony4 sylius sylius-1.3


【解决方案1】:

这是我的 orm 文件。 AppBundle/Resources/config/doctrine/Country.orm.yml

对于 v1.3,orm 文件应该放在src\Resources\config\doctrine

另外,php bin/console debug:config sylius_addressing 的结果是什么?

//2018-12-18

不妨试试:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Addressing\Model\Country as BaseCountry;

/**
 * Class Country
 * @package App\Entity
 * @ORM\Table(name="sylius_country")
 * @ORM\Entity
 */
class Country extends BaseCountry {

【讨论】:

  • 它是相同的路径 src\Resources\config\doctrine.but 那不起作用。
  • 任何错误信息? php bin/console debug:config sylius_addressing 的结果是什么?
  • 当我运行这个命令 'php bin/console debug:config sylius_addressing' 然后显示国家类是 ...country: classes: model: Sylius\Component\Addressing\Model\Country interface: Sylius\ Component\Addressing\Model\CountryInterface 控制器:Sylius\Bundle\ResourceBundle\Controller\ResourceController 工厂:Sylius\Component\Resource\Factory\Factory 形式:Sylius\Bundle\AddressingBundle\Form\Type\CountryType
  • 尝试在 Country.php 上添加注释(请参阅上面带有标签 //2018-12-18 的我的更新)
  • 解决了吗?我发现您的配置文件位置似乎错误。你应该放在包文件夹下:config\packages\_sylius.yaml
【解决方案2】:
  1. type: mappedSuperclass 在教义映射中
  2. 确保AppBundle 扩展AbstractResourceBundle
  3. 确保AppBundle 具有protected $mappingFormat = ResourceBundleInterface::MAPPING_YAML;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多