我正在根据这个讨论创建一个子域监听器Symfony2 Routing - route subdomains
所以它交给了这个听众,我可以做我想做的事情。
但我无法用我的一个控制器扩展这个监听器。监听器代码是这样的......
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());
}
}
但是当我尝试运行时它会抛出
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
因此,当我尝试调试它时,它实际上会通过扩展类,但最后在 Controller 中它无法处理 get()。
是否有解决方法来访问 Listener 中的控制器功能?