duangao8359 2012-10-30 05:19
浏览 44

如何在symfony2中使用控制器扩展Listener?

I am creating a Subdomain Listener as per this discussion Symfony2 Routing - route subdomains

So it goes to this listener and I can do the stuff I want to.

But I am not able to extend this listener with one of my controllers. listener code goes like this ...

namespace Acme\FrontEndBundle\Listener;

use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Response;
use Acme\BraPrintBundle\Controller\BraPrintController;
use Symfony\Component\HttpFoundation\RedirectResponse;

use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;

class SubdomainListener extends BraPrintController
{
   public function onDomainParse(Event $event)
   {
       $request = $event->getRequest();
       $session = $request->getSession();
       echo $request->getHost();
       echo $this->isLoggedIn(); // defined in BraprintController
       // todo: parsing subdomain to detect country
       //do some auth stuff
       //$session->set('corporate', $request->getHost());
   }
}

But when I try to run it throws

Fatal error: Call to a member function get() on a non-object in /home/myname/myproject/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php on line 192

So when I try to debug it actully goes through extended classes but at the end in Controller its not able to deal with get().

Is there a work around to access controller functions in Listener ?

  • 写回答

1条回答 默认 最新

  • duanji8615 2012-10-30 10:19
    关注

    use Symfony\Component\HttpFoundation\Request;

    $request = Request::createFromGlobals();

    This is an alternative to interact with the HTTP request and response in an easier way.

    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来