FOSJsRoutingBundle - 路线" xxx"不存在

时间:2017-01-28 13:23:23

标签: ajax symfony nginx

我使用fosJsRouting为我的ajax调用生成路由。

操作系统:Ubuntu 16.04 + nginx + php 7

app/Kernel.php
    public function registerBundles()
    {
        $bundles = array(
            new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
            );

配置......

app/config/config.yml
fos_js_routing:
    resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"

fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"
app:
    resource: "@AppBundle/Controller/"
    type:     annotation

这是捆绑路由

pablo_user_getonline:
    path:     user/getonline
    defaults: { _controller: pabloUserBundle:User:getonline }
    methods:  [POST,GET]
    options: { expose: true }

Js:

$(document).ready(function(){
        $.ajax({
            url: "pablo_user_getonline",
            method: "POST",
            data:[],
            success: function (result) {

                $('#delete-progress').addClass('hidden');

                if(result.data == 1)
                {
                    alert("Status changed");
                }
                else
                {
                    $('#message-danger').removeClass('hidden');

                    $('#user-message-danger').text(result.message);
                }
            }}).fail(function(){
            alert('ERROR');
        });
});

布局......

{% block javascripts %}
<script src="{{ asset('public/js/jquery-3.1.0.min.js') }}"></script>
<script src="{{ asset('public/js/bootstrap.min.js') }}"></script>
<script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
<script src="{{ asset('bundles/pablouser/js/bootbox.min.js') }}"></script>
<script src="{{ asset('bundles/pablouser/js/set-online.js') }}"></script>
<script src="{{ asset('bundles/pablouser/js/get-online.js') }}"></script>
<script src="{{ asset('bundles/pablouser/js/noty/packaged/jquery.noty.packaged.min.js') }}"></script>
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
{% endblock %}

当我运行app / console fos:js-routing:debug得到这个:

+------------------------------+-------------+--------+------+------------------------------+
| Name                         | Method      | Scheme | Host | Path                         |
+------------------------------+-------------+--------+------+------------------------------+
| pablo_user_getonline         | POST|GET    | ANY    | ANY  | /user/getonline              |
| pablo_user_setonline         | POST        | ANY    | ANY  | /user/setonline              |
| pablo_publication_index      | ANY         | ANY    | ANY  | /publication/index           |
| pablo_publication_delete     | POST|DELETE | ANY    | ANY  | /publication/delete/{id}     |
| pablo_publication_seoprocess | POST        | ANY    | ANY  | /publication/seoprocess/{id} |
| get_domain_info_ajax         | POST        | ANY    | ANY  | /getAjaxDomainInfo           |
| register_domain              | POST        | ANY    | ANY  | /registerDomain              |
+------------------------------+-------------+--------+------+------------------------------+

在Routing.generate中找到任何此路由。

我一直在四处寻找解决方案,所以我试图:

  • 将options设置为expose = true
  • 添加此路线以展示到app / config / config.yml
  • Symfony缓存很清楚
  • 已安装资产。

1 个答案:

答案 0 :(得分:0)

要生成您的网址,您应该使用Routing.generate(path, parameters)

url: Routing.generate("pablo_user_getonline"),

您还应该添加

<script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>

定义为here in the documentation