异常Symfony \ Component \ Routing \ Exception \ ResourceNotFoundException [Symfony 2.4]

时间:2014-11-15 18:19:50

标签: php symfony routing routes

我正在使用一个自定义控制器,我的所有其他控制器将扩展而不是Symfony的基本控制器类。

除了一条路线(在localhost btw上工作正常),prod env中的一切正常。

以下是导致此异常的路由:

acme_change_lang:
    pattern:  /changeLang/{locale}/
    defaults: { _controller: AcmeBundle:Acme:changeLang}

CoreController:

class CoreController extends Controller
{
    private $_locales;

    public function __construct() {
        //if set to true then the language is active. False means the language cannot be used at the moment.
        $this->_locales = array('en' => true, 'fr' => true);
    }

    .....

    protected function getRefererRoute(Request $request = null)
    {
        if ($request == null)
            $request = $this->getRequest();

        //look for the referer route
        $referer = $request->headers->get('referer');
        $lastPath = substr($referer, strpos($referer, $request->getBaseUrl()));
        $lastPath = str_replace($request->getBaseUrl(), '', $lastPath);

        $matcher = $this->get('router')->getMatcher();
        $parameters = $matcher->match($lastPath);
        $route = $parameters['_route'];

        return $route;
    }

    protected function setSession(Request $request, $loc = '') {
        $session = $request->getSession();

        if (empty($loc) OR !isset($this->_locales[$loc]) OR $this->_locales[$loc] == false)
            $loc = 'en';
        $session->set('locale', $loc);
    }

    public function changeLangAction(Request $request, $locale) {
        $this->setSession($request, $locale);
        return ($this->redirect($this->generateUrl($this->getRefererRoute($request))));
    }

   .....
}


[2014-11-15 18:54:14] request.INFO: Matched route "acme_change_lang" (parameters: "_controller": "Acme\Bundle\AcmeBundle\Controller\AcmeController::changeLangAction", "locale": "en", "_route": "acme_change_lang") [] []
[2014-11-15 18:54:14] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Routing\Exception\ResourceNotFoundException: "" at /home/fakePath/www/app/cache/prod/appProdUrlMatcher.php line 66 {"exception":"[object] (Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException:  at /home/fakePath/www/app/cache/prod/appProdUrlMatcher.php:66)"} []

我不明白的是,它说它找到了匹配的路线,然后抛出了这个异常。

关于导致这种情况的任何想法?

0 个答案:

没有答案