为什么我的文件更新监听器不像sylius项目上的variant_image一样工作? [英] Why my file-update Listener don't work like variant_image on sylius project?

查看:194
本文介绍了为什么我的文件更新监听器不像sylius项目上的variant_image一样工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用独立版本的SyliusResourceBundle(0.9)。
我可以管理没有任何问题我的实体:用户,组,角色和公司。

我尝试使用Gaufrette \Filesystem为公司添加徽标(如sylius中的variant_image)。
似乎我的服务没有运行。他试图坚持图像没有被上传,我没有错误信息从我的听众!

KNP Gaufrette配置在config.yml:











$目录%kernel.root_dir% ../web/media/file
create:true
文件系统:
project_file:
适配器: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 ,前夕nt:project.company.pre_update,方法:uploadCompanyLogo}

#其他
project.image_uploader:
class:%project.image_uploader.class%
factory_class:Gaufrette \文件系统
factory_service:knp_gaufrette.filesystem_map
factory_method:get
参数:[project_file]

My ImageUploadListener:

 <?php 

名称空间Project \ CoreBundle\EventListener;

使用Project\CompanyBundle\Entity\CompanyInterface;
使用Project\CoreBundle\Uploader\ImageUploaderInterface;
使用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(); ($ logo-> hasFile()){
$ this->上传者 - >上传($ logo);





$ / code $ / pre

一个图像,我得到这个消息:

pre $ 执行'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]:完整性约束违反:1048列路径不能为空

我觉得我的服务不会触发,任何人都可以帮我解决这个问题?



感谢:)

解决方案

好像图片上传功能仍在开发中。我注意到,当已经有一个图像集合的一部分,像创建这个github问题的人一样,图片上传器不工作: issue#356 。有关于可以做什么/可以使用什么工具来开发更好的上传器的讨论: link a>。


I use a standalone version of SyliusResourceBundle (0.9) in my project. I can manage without any problem my entities: User, Group, Role and Company.

I tried using Gaufrette\Filesystem to add a logo to a company (like variant_image in sylius). And it seems that my service is not running. He tries to persist the image without it have been uploaded and I have no error message from my listener !

KNP Gaufrette Configuration in config.yml :

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]

My 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);
        }
    }
}

When i send my form with an image, i got this message :

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

I feel that my service does not fire, Anyone can help me with this problem ?

Thanks :)

解决方案

It seems like the image uploader feature is still being developed. I've noticed that the image uploader doesn't work when there's already an image that's part of the collection as did the person who created this github issue: issue #356. There's discussion on what could be done/what tools could be used to develop a better uploader here: link.

这篇关于为什么我的文件更新监听器不像sylius项目上的variant_image一样工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆