1 回答
TA贡献1820条经验 获得超2个赞
所以这就是我解决它的方法:
将请求堆栈添加到服务:
<service id="myservice>
<argument type="service" id="request_stack"/>
</service>
然后得到这样的控制器:
// src/AppBundle/EventListener/AcmeListener.php
namespace AppBundle\EventListener;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
class AcmeListener
{
/** @var Request */
protected $request;
/**
* AcmeListener constructor.
*
* @param RequestStack $requestStack
*/
public function __construct(RequestStack $requestStack)
{
$this->request = $requestStack->getCurrentRequest();
}
/**
* @param LifecycleEventArgs $args
*/
public function postLoad(LifecycleEventArgs $args)
{
$controller = $this->request->attributes->get('_controller');
if (strpos($controller, 'DontTriggerController::indexAction') !== false) {
// Do nothing
return;
}
// Do somethings
}
}
希望这可以帮助某人
- 1 回答
- 0 关注
- 118 浏览
添加回答
举报