0

当我尝试创建路径变量时:

{% 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.")
4

1 回答 1

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)
于 2013-10-04T08:33:14.073 回答