php - symfony 4 中没有服务 FOSJsRoutingBundle

标签 php symfony bundle

错误:

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/

相关文章:

php - 为什么我得到 undefined index

doctrine-orm - Symfony 项目应该如何在其实体类中实现 UML2 类接口(interface)?

elasticsearch - OXID shop和ONGR如何建立连接?

ruby-on-rails - 无法 bundle/安装Kgio错误

php - 体验与框架 : PHP vs Rails

php - VPS 重新启动后,OpenLiteSpeed Cyber​​Panel 上的 Wordpress 出现 404 错误

php - Symfony2 Twig 注入(inject)额外的 block

php - 无法使用 RabbitMQ 和 Symfony2 发送 Swift_Message

ios - 无法将文件从包复制到 iOS 中的文档目录

javascript - 如何在 gulp 的嵌套目录中 bundle 多个文件?