Symfony 2 BlueImp OneupUploaderBundle sql 错误 PostPersistEvent 不工作

Symfony 2 BlueImp OneupUploaderBundle sql error PostPersistEvent not working

我正在尝试构建一个事件监听器,以便在创建实体时将图像的路径(url)持久保存到数据库中。我正在使用 Blueimp (jQuery-File-Uploader)。 但是我遇到了 sql 异常。我猜有些东西没有链接到我的听众。

An exception occurred while executing 'INSERT INTO Image (name, url) VALUES (?, ?)' with params ["dasdasdas", null]

我的config.yml

oneup_uploader:
mappings:
    gallery:
        frontend: blueimp

我的service.yml

services:
app.bundle.upload_listener:
    class: AppBundle\Eventlistener\ImageuploadListener
    arguments: ["doctrine.orm.entity_manager"]
    tags:
        -  { name: kernel.event_listener,  event: oneup_uploader.post_persist, mehtod: onPostUpload}

我的形象实体

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;    
/**
 * Image
 *
 * @ORM\Table()
 * @ORM\Entity
 */
class Image
{
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var string
 *
 * @ORM\Column(name="name", type="string", length=255)
 */
private $name;

/**
 * @var string
 *
 * @ORM\Column(name="url", type="string", length=255)
 */
private $url;


/**
 * Get id
 *
 * @return integer 
 */
public function getId()
{
    return $this->id;
}

/**
 * Set name
 *
 * @param string $name
 * @return Image
 */
public function setName($name)
{
    $this->name = $name;

    return $this;
}

/**
 * Get name
 *
 * @return string 
 */
public function getName()
{
    return $this->name;
}

/**
 * Set url
 *
 * @param string $url
 * @return Image
 */
public function setUrl($url)
{
    $this->url = $url;

    return $this;
}

/**
 * Get url
 *
 * @return string 
 */
public function getUrl()
{
    return $this->url;
}
}

我的图片上传监听器

namespace AppBundle\Eventlistener;

use AppBundle\Entity\Image;
use Oneup\UploaderBundle\Event\PostPersistEvent;

class ImageuploadListener
{
protected $manager;

public function __construct(\Doctrine\ORM\EntityManager $manager)
{
 $this->manager = $manager;

}

public function onPostUpload(PostPersistEvent $event)
{   

    $file = $event->getFile();

    $object = new Image();
    $object->setUrl($file->getPathName());

    $this->manager->persist($object);
    $this->manager->flush();
}

}

我收到 jquery 500 错误,但图像已移至文件夹。权限正常(所有权限)。

POST http://localhost:8000/_uploader/gallery/upload 500 (Internal Server Error)

编辑:我在错误日志中发现了这个:

 [2015-04-03 11:23:23] event.INFO: An exception was thrown while getting the uncalled listeners (Catchable Fatal Error: Argument 1 passed to AppBundle\Eventlistener\ImageuploadListener::__construct() must be an instance of AppBundle\Eventlistener\EntityManager, array given, called in D:\x...\app\cache\dev\appDevDebugProjectContainer.php on line 359 and defined) {"exception":"[object] (Symfony\Component\Debug\Exception\ContextErrorException(code: 0): Catchable Fatal Error: Argument 1 passed to AppBundle\Eventlistener\ImageuploadListener::__construct() must be an instance of AppBundle\Eventlistener\EntityManager, array given, called in D:\....\app\cache\dev\appDevDebugProjectContainer.php on line 359 and defined at D:\...\src\AppBundle\Eventlistener\ImageuploadListener.php:12)"} []

编辑 2:我已将我的 EntityManager 更改为 \Doctrine\ORM\EntityManager 现在我遇到了不同的错误 (dev.log):

 request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Warning: call_user_func() expects parameter 1 to be a valid callback, class 'AppBundle\Eventlistener\ImageuploadListener' does not have a method 'onOneupuploaderPostpersist'" at D:\...\vendor\symfony\symfony\src\Symfony\Component\EventDispatcher\Debug\WrappedListener.php line 61

知道为什么吗?可以请有人向我解释我做错了什么吗?哪个文件调用了这个方法 onOneuploaderPostpersist ?

在你的文件中service.yml

mehtod: onPostUpload

是拼写错误,而不是“mehtod”你应该有“method

如果没有另外指定,这个方法可能是 OneupUploaderBundle 在侦听器上调用的默认方法