OneupUploaderBundle upload picture but doesn't call EventListener
Asked Answered
C

1

1

I have this Bundle working on my Symfony2 app. Images are well uploaded, but the listener for persist the filename to the SQL table is not called on method onUpload.

Is strange, because all looks to be in order...

This is my services.yml

services:
luisma.upload_listener:
    class: "LuismaBundle\Services\UploadListener"
    arguments: [@doctrine]
    tags:
        - { name: 'kernel.event_listener', event: oneup_uploader.post_persist, method: onUpload }

And this is my Listener:

 <?php

namespace LuismaBundle\Services;

use Oneup\UploaderBundle\Event\PostPersistEvent;
use LuismaBundle\Entity\MotorsAdsFile;

class UploadListener
{
    protected $manager;

    public function __construct(EntityManager $manager)
    {
        $this->manager = $manager;
    }

    public function onUpload(PostPersistEvent $event)
    {
        $file = $event->getFile();

        $object = new MotorsAdsFile();
        $object->setFilename($file->getPathName());
        $this->manager->persist($object);
        $this->manager->flush();
    }
}

Could be great if somebody can give any suggestion! Thanks in advance!!

Caputo answered 30/8, 2015 at 12:17 Comment(1)
I have the same problem on Symfony 3.1.2 (UploadListener is not called, but uploads work fine). Did you get any solution for your problem?Mort
H
0

Remove apostrophes around kernel.event_listener

Hebner answered 30/8, 2015 at 13:14 Comment(3)
Thanks, but still same. Looks like the post_persist event is not working there...Caputo
I don't know, I have the same config, but without apostrophes. If I try add it around class name in service, I cannot upload any image.Hebner
Also tried to remove apostrophes, but sadly result is still the same: upload listener is not called.Mort

© 2022 - 2024 — McMap. All rights reserved.