【发布时间】:2016-09-08 00:03:54
【问题描述】:
在我的 Symfony2 控制器中,这可以正常工作:
$uploadManager = $this->get('upload.upload_manager');
但是当我将其移至自定义侦听器时:
use Doctrine\ORM\Event\LifecycleEventArgs;
use Acme\UploadBundle\Upload\UploadManager;
class PersonChange
{
public function postRemove(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
$entityManager = $args->getEntityManager();
$uploadManager = $this->get('ep_upload.upload_manager');
echo "the upload dir is " . $uploadManager->getUploadDir();
}
}
我收到一个错误:
Fatal error: Call to undefined method Acme\MainBundle\Listener\PersonChange::get() in /home/frank/...
我知道我必须需要一个 use 语句,但不知道该使用什么。
【问题讨论】:
-
这应该提供一个可能的解决方案:How do I get services dependencies in a custom class
标签: symfony