我有一个必须能够管理图像文件的自定义实体(活动),所以我可以通过管理员上传一个。我已经尝试以 Taxon 实体为例。问题是,当尝试通过管理表单创建新活动时,它会返回以下错误:
可捕获的致命错误:传递给 Sylius\Bundle\CoreBundle\Entity\Campaign::setFile() 的参数 1 必须是 SplFileInfo 的实例,给定字符串,在 /NetBeansProjects/tiendacoleman/vendor/symfony/symfony/src/Symfony/Component 中调用/PropertyAccess/PropertyAccessor.php 在第 350 行并在 /NetBeansProjects/tiendacoleman/src/Sylius/Bundle/CoreBundle/Entity/Campaign.php 第 100 行中定义
namespace Sylius\Bundle\CoreBundle\Entity;
use Sylius\Bundle\CoreBundle\Model\ImageInterface;
use SplFileInfo;
use DateTime;
class Campaign implements ImageInterface
{
protected $id;
protected $campaign;
protected $link;
protected $isActive;
protected $campaignOrder;
/**
* @var SplFileInfo
*/
protected $file;
/**
* @var string
*/
protected $path;
/**
* @var \DateTime
*/
protected $createdAt;
/**
* @var \DateTime
*/
protected $updatedAt;
public function __construct()
{
$this->createdAt = new DateTime();
}
public function getId()
{
return $this->id;
}
public function getCampaign()
{
return $this->campaign;
}
public function setCampaign($campaign)
{
$this->campaign = $campaign;
}
public function getLink()
{
return $this->link;
}
public function setLink($link)
{
$this->link = $link;
}
public function getIsActive()
{
return $this->isActive;
}
public function setIsActive($isActive)
{
$this->isActive = $isActive;
}
public function getCampaignOrder()
{
return $this->campaignOrder;
}
public function setCampaignOrder($campaignOrder)
{
$this->campaignOrder = $campaignOrder;
}
public function hasFile()
{
return null !== $this->file;
}
public function getFile()
{
return $this->file;
}
public function setFile(SplFileInfo $file)
{
$this->file = $file;
}
public function hasPath()
{
return null !== $this->path;
}
public function getPath()
{
return $this->path;
}
public function setPath($path)
{
$this->path = $path;
}
public function getCreatedAt()
{
return $this->createdAt;
}
public function setCreatedAt(DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
public function getUpdatedAt()
{
return $this->updatedAt;
}
public function setUpdatedAt(DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;
}
}
这是表单的代码:
namespace Sylius\Bundle\CoreBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class CampaignType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('campaign', 'text', array(
'label' => 'sylius.form.campaign.name'
))
->add('link', 'text', array(
'label' => 'sylius.form.campaign.link'
))
->add('isActive', 'checkbox', array(
'label' => 'sylius.form.campaign.active'
))
->add('file','file',array(
'label' => 'sylius.form.campaign.file'
))
;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'sylius_campaign';
}
}
非常感谢您的帮助!