![](/img/trans.png)
[英]Symfony 3.1 and OneUpUploaderBundle + Blueimp = UploadListener is not called
[英]Symfony 2 BlueImp OneupUploaderBundle sql error PostPersistEvent not working
我正在嘗試構建一個Eventlistener,以便在創建實體時將圖像的路徑(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;
}
}
我的imageuploadListener
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
知道為什么嗎? 可以請人向我解釋我做錯了什么嗎? 哪個文件在OneupuploaderPostpersist上調用此方法?
在您的文件service.yml中
mehtod: onPostUpload
是拼寫錯誤,而不是“ mehtod ”,您應該使用“ method ”
如果未指定,則此方法可能是OneupUploaderBundle在偵聽器上調用的默認方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.