当我尝试创建路径变量时:
{% block jquery %}
<script>var url = "{{ path('bundles/foo/ajax/widb-get-data.php') }}";</script>
{% endblock %}
我收到以下错误:
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "FooBundle:Default:myfile.php" as such route does not exist.")
答案 0 :(得分:1)
我建议您使用FOSJsRoutingBundle
然后你可以这样做:<script>
var url = Routing.generate('route_id', /* your params */);
</script>
请注意,您正在呼叫路线而不是文件
为了通过routing.generate
调用控制器中声明的路由,请务必在之前公开:
/**
* @Route("/foo/{id}/bar", name="my_route_to_expose", options={"expose"=true})
*/
public function exposedAction($foo)