gpt4 book ai didi

javascript - (Symfony 4) FOS Js Routing Bundle - 路由 ------ 不存在。

转载 作者:行者123 更新时间:2023-11-30 19:56:53 25 4
gpt4 key购买 nike

似乎路由 yml 文件没有被 Fos Js 路由包获取。这是我到目前为止所做的:

设置:

$./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 中:

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

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

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 中:

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

在我的 javascript .js 文件中:

$(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 控制台中我收到错误:

Error: The route "add_post_comment" does not exist.

也许它没有看到 yaml 文件?我缺少一个步骤吗?

我也重启了nginx。

最佳答案

您不会像这样公开您的路线:

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

关于javascript - (Symfony 4) FOS Js Routing Bundle - 路由 ------ 不存在。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53890929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com