为什么我的文件更新监听器在sylius项目中不像variant_image那样工作?

时间:2014-05-23 16:18:11

标签: symfony file-upload listener sylius

我在项目中使用了独立版本的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

我觉得我的服务没有解雇,任何人都可以帮我解决这个问题?

谢谢:)

1 个答案:

答案 0 :(得分:0)

似乎图像上传器功能仍在开发中。我注意到图像上传器在已经创建此github问题的人的图像中已经是一部分图像时不起作用:issue #356。在这里讨论可以做什么/可以用什么工具来开发更好的上传者:link