我有这个Bundle在我的Symfony2应用程序上工作。图像上传得很好,但是用于将文件名持久化到SQL表的侦听器没有在onUpload方法上调用。
很奇怪,因为一切看起来都井然有序…
This is my services.yml
services:
luisma.upload_listener:
class: "LuismaBundleServicesUploadListener"
arguments: [@doctrine]
tags:
- { name: 'kernel.event_listener', event: oneup_uploader.post_persist, method: onUpload }
这是我的听众:
<?php
namespace LuismaBundleServices;
use OneupUploaderBundleEventPostPersistEvent;
use LuismaBundleEntityMotorsAdsFile;
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();
}
}
如果有人能给点建议就太好了!提前感谢!! 去掉kernel.event_listener
的撇号