【问题标题】:Sylius\Component\Shipping\Model\ShippingMethodTranslation must be compatible with Sylius\Component\Shipping\Model\ShippingMethod::createTranslation():Sylius\Component\Shipping\Model\ShippingMethodTranslation 必须与 Sylius\Component\Shipping\Model\ShippingMethod::createTranslation() 兼容:
【发布时间】:2017-11-22 10:37:20
【问题描述】:

我正在学习教程:“如何自定义可翻译模型?”在 Sylius 文档中。

当我运行命令时:php bin/console dictionary:migrations:diff 我得到了这个错误:

致命错误:AppBundle\Entity\ShippingMethod::createTranslation() 声明:Sylius\Component\Shipping\Model\ShippingMethodTranslation 必须与 Sylius\Component\Shipping\Model\ShippingMethod::createTranslation() 兼容:Sylius\Component第 8 行 C:\wamp64\www\acme7\src\AppBundle\Entity\ShippingMethod.php 中的 \Shipping\Model\ShippingMethodTranslationInterface

这是我的课:

<?php

namespace AppBundle\Entity;

use Sylius\Component\Core\Model\ShippingMethod as BaseShippingMethod;
use Sylius\Component\Shipping\Model\ShippingMethodTranslation;

class ShippingMethod extends BaseShippingMethod
{
    /**
     * @var string
     */
     private $estimatedDeliveryTime;

    /**
     * @return string
     */
    public function getEstimatedDeliveryTime(): string
    {
        return $this->estimatedDeliveryTime;
    }

    /**
     * @param string $estimatedDeliveryTime
     */
    public function setEstimatedDeliveryTime(string $estimatedDeliveryTime): void
    {
         $this->estimatedDeliveryTime = $estimatedDeliveryTime;
    }

    /**
     * {@inheritdoc}
     */
     protected function createTranslation(): ShippingMethodTranslation
     {
    return new ShippingMethodTranslation();
     }
}

关于如何解决这个问题的任何想法?

【问题讨论】:

    标签: php sylius


    【解决方案1】:

    我从 sylius 的松弛中得到了一些帮助。

    因为我使用的是 Sylius v1.0.4

    我不得不更换:

    use Sylius\Component\Shipping\Model\ShippingMethodTranslation;
    

    通过

    use Sylius\Component\Shipping\Model\ShippingMethodTranslationInterface;
    

    /**
     * {@inheritdoc}
     */
      protected function createTranslation(): ShippingMethodTranslation
      {
            return new ShippingMethodTranslation();
    }
    

    /**
     * {@inheritdoc}
     */
    protected function createTranslation(): ShippingMethodTranslationInterface {
        return new ShippingMethodTranslation();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-13
      • 2017-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多