I have a controller that renders a fragment of a page; and it may be refreshed using ajax. Until now, this controller uses this at the top:
if ('/_fragment' !== $request->getPathInfo() && !$request->isXmlHttpRequest()) {
throw $this->createNotFoundException();
}
This works well, but I seen that there is a condition
option in the @Route
annotation, and wanted to use it instead:
/**
* @Route(
* "/widget/render/{cryptedId}",
* name = "widget_render",
* requirements = {
* "cryptedId" = "^[a-zA-Z0-9]+$"
* },
* condition = "'/_fragment' == request.getPathInfo() or request.isXmlHttpRequest()"
* )
* @Method({"GET"})
* @Template()
*/
But adding this option gives me the following error:
FatalErrorException in appDevUrlMatcher.php line 319:
-> Error: Call to a member function getPathInfo() on a non-object
That's strange, because from the documentation, context
and request
are available in the expression parser. By looking at the source code, in UrlMatcher.php, we can see that they should be available:
if ($route->getCondition() && !$this->getExpressionLanguage()->evaluate($route->getCondition(), array('context' => $this->context, 'request' => $this->request))) {
return array(self::REQUIREMENT_MISMATCH, null);
}
I really don't get the point. Any clue?