我在我的项目中使用了 SyliusResourceBundle (0.9) 的独立版本。我可以毫无问题地管理我的实体:用户、组、角色和公司。
我尝试使用 Gaufrette\Filesystem 向公司添加徽标(例如 sylius 中的 variant_image)。而且似乎我的服务没有运行。他试图在没有上传图像的情况下保留图像,我的听众没有错误消息!
config.yml 中的 KNP Gaufrette 配置:
knp_gaufrette:
adapters:
project_file:
local:
directory: %kernel.root_dir%/../web/media/file
create: true
filesystems:
project_file:
adapter: project_file
ProjectCoreBundle\Resources\Config\services.yml :
#in ProjectCoreBundle\Resources\Config\services.yml
# Listener
project.listener.image_upload:
class: %project.listener.image_upload.class%
arguments: ['@project.image_uploader']
tag:
- { name: kernel.event_listener, event: project.company.pre_create, method: uploadCompanyLogo }
- { name: kernel.event_listener, event: project.company.pre_update, method: uploadCompanyLogo }
# Other
project.image_uploader:
class: %project.image_uploader.class%
factory_class: Gaufrette\Filesystem
factory_service: knp_gaufrette.filesystem_map
factory_method: get
arguments: [project_file]
我的 ImageUploadListener :
<?php
namespace Project\CoreBundle\EventListener;
use Project\CompanyBundle\Entity\CompanyInterface;
use Project\CoreBundle\Uploader\ImageUploaderInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class ImageUploadListener
{
protected $uploader;
public function __construct(ImageUploaderInterface $uploader)
{
$this->uploader = $uploader;
}
public function uploadCompanyLogo(GenericEvent $event)
{
$subject = $event->getSubject();
if (!$subject instanceof CompanyInterface) {
throw new UnexpectedTypeException(
$subject,
'Project\CompanyBundle\CompanyInterface');
}
$logo = $subject->getLogo();
if ($logo->hasFile()) {
$this->uploader->upload($logo);
}
}
}
当我发送带有图像的表单时,我收到了以下消息:
An exception occurred while executing 'INSERT INTO syn_image (path, createdAt, updatedAt) VALUES (?, ?, ?)' with params [null, "2014-05-23 18:13:13", "2014-05-23 18:13:13"]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'path' cannot be null
我觉得我的服务没有触发,任何人都可以帮助我解决这个问题吗?
谢谢 :)