(Symfony 4)FOS Js路由捆绑包-路由-------不存在。 [英] (Symfony 4) FOS Js Routing Bundle - The route ------- does not exist.

查看:122
本文介绍了(Symfony 4)FOS Js路由捆绑包-路由-------不存在。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Fos Js Routing捆绑包似乎没有拾取yml路由文件。到目前为止,这是我所做的:

It seems like the routing yml file isn't being picked up by the Fos Js Routing bundle. Here's what I have done so far:

设置:

$./composer.phar  require friendsofsymfony/jsrouting-bundle
$bin/console assets:install --symlink public
$bin/console fos:js-routing:dump --format=json --target=public/js /fos_js_routes.json

在base.html.twig中:

In base.html.twig:

<script src="{{ asset('bundles/fosjsrouting/js/router.min.js') }}"></script>
<script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>

在单独的.js模块文件中:

In a separate .js module file:

const routes = require('../../public/js/fos_js_routes.json');
import Routing from '../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js';

在config\routes.yaml中:

In config\routes.yaml:

add_post_comment:
    path:   /comment/add/post
    controller: App\Controller\CreatorDashboard\CommentController::addPostComment
    requirements:
     _method:  POST

在我的javascript .js文件中:

In my javascript .js file:

$(document).ready(function() {
    $(".post-comment").keyup(function(e) {

        var code = e.which;
        if(code==13)
        {
            var commentText = $(this).val();
            var postId = $(this).data("postid");
            var userId= $(this).data("userid");

            console.log("userId is " + userId + " and postId is " + postId + " and commentText is " + commentText);
            var theRoute = Routing.generate('add_post_comment'); // have also tried Routing.generate('/comment/add/post'); 
            alert("the route is " + theRoute);

在JavaScript控制台中,我得到了错误:

In the JavaScript console I get the error:

Error: The route "add_post_comment" does not exist.

也许看不到yaml文件?我缺少步骤了吗?

Maybe it doesn't see the yaml file? Is there a step I'm missing?

我还重新启动了Nginx。

I have also restarted nginx.

推荐答案

您不会像这样暴露路线:

You are not exposing your route like this:

# app/config/routing.yml
my_route_to_expose:
    pattern: /foo/{id}/bar
    defaults: { _controller: AppBundle:Default:index }
    options:
        expose: true

这篇关于(Symfony 4)FOS Js路由捆绑包-路由-------不存在。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆