我遵循教程:"如何自定义可翻译的模型?"在Sylius doc。
当我运行命令时:php bin / console doctrine: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();
}
}
关于如何解决这个问题的任何想法?
答案 0 :(得分:0)
我从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();
}