为php文件创建路径会生成路径未找到错误

时间:2013-10-04 03:22:11

标签: symfony

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

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

1 个答案:

答案 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)