gpt4 book ai didi

php - symfony 4 中没有服务 FOSJsRoutingBundle

转载 作者:行者123 更新时间:2023-12-03 00:06:54 24 4
gpt4 key购买 nike

错误:

An exception has been thrown during the rendering of a template 

"You have requested a non-existent service "C". Did you mean one of
these: "Symfony\Bundle\FrameworkBundle\Controller\RedirectController",
"Symfony\Bundle\FrameworkBundle\Controller\TemplateController

如何在 symfony 4 中打开 FOSJsRoutingBundle?

bundles.php:

FOS\JsRoutingBundle\FOSJsRoutingBundle::class => ['all' => true] 

routes.yaml:

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

layout.html.twig:

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

最佳答案

你使用webpack吗?如果是,则无需将此代码包含到模板中:

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

您所要做的就是运行此命令:

bin/console fos:js-routing:dump --format=json --target=public/js/fos_js_routes.json

然后将此代码包含到 Assets 文件夹中的 .js 文件中:

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

Routing.setRoutingData(routes);
Routing.generate('rep_log_list');

本指南引用此文档:FOSJsRouting Usage

关于php - symfony 4 中没有服务 FOSJsRoutingBundle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48763659/

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