我正在 Symfony 4 中开发一个需要 FOSJSrouting 包的页面。在我的开发环境中 - 使用 docker - 我使用以下步骤使其工作正常。
但是,在我的产品环境中,我不断收到错误:
- http://url/js/routing?callback=fos.Router.setData 500 (Internal Server Error)
- router.min.js:1 Uncaught Error: The route "get_coinTicker_from_platform" does not exist.
让它在 DEV 中运行的步骤:
-
$ composer require friendsofsymfony/jsrouting-bundle
将以下内容添加到
routes.yaml
:fos_js_routing: resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"
将以下内容添加到我的 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>
这足以让我公开的路线发挥作用:
/**
* @Route("/ticker/{coin}/{plat}", name="get_coinTicker_from_platform", options={"expose"=true})
*/
然后在我的 JavaScript 中我做了:
$.ajax({
method: 'POST',
url: Routing.generate('get_coinTicker_from_platform', {coin: coin.val(), plat: exch.val()})
}).done(function(data) {
$('.loader').hide();
}
});
我在 Linux 服务器上使用 Composer 安装了路由包,甚至尝试了文档中包含的步骤来发布 Assets 以及转储路由,如下所示:
bin/console fos:js-routing:dump --format=json --target=public/js/fos_js_routes.json
我检查了 symfony 和 Apache 日志。那里没有任何暗示这个问题。其他一切都运行良好,只是 FOSrouting 造成了麻烦。 另外,我尝试过:
npm install fos-routing --save
这实际上暂时解决了问题,但第二天,在我从本地存储库执行另一个 rsync 后,它再次被破坏。
最佳答案
我遇到了同样的问题,通过在文件夹 var/cache/prod
上提供正确的 rwxrwxrwx
解决了这个问题。
关于javascript - 4 FOSJSRouting 回调=fos.Router.setData & 仅在生产中找不到路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50796430/