Mis*_*erJ 21 javascript php symfony
我正面临一个FOSJSRoutingBundle的一个非常奇怪的问题:
首先,这是我的配置:我正在使用Symfony 2.0.23和JQuery,在Windows 7 64位上使用WAMP(Apache 2.4.2和PHP 5.4.3).我已经完成了FOSJSRoutingBundle的github中的所有设置并暴露了我的路线(几乎所有我通过谷歌搜索找到的相关问题(在FOSJSRoutingBundle的github,这里和不同的论坛上)是因为人们没有暴露他们的路线,但我试过php app/console fos:js-routing:debug我看到了我的路线).js被添加到布局中(结尾处的布局代码).
尝试为js中的路由生成url,在开始时我想生成两个不同的路由但是为了测试我在下面创建了js代码:
//Code inside this function is working
$("select").change(function () {
param=this.options[this.selectedIndex].value;
test1=Routing.generate('myBundle_step3', { myParam: param });
alert(test1);
window.location=Routing.generate('myBundle_step2');
});
//Code inside this one is also working
$('input[type="checkbox"]').change(function() {
test=Routing.generate('myBundle_step2');
}).change();
//This is not working
test=Routing.generate('myBundle_step2');
alert(test);
Run Code Online (Sandbox Code Playgroud)
使用此代码,我得到javaScript错误"路径myBundle_step2不存在".虽然第一部分仍然有效(警报给我创建的链接,重定向很顺利).如果我删除第二个函数,我不再得到Javascript错误.如果在第二个函数中我将步骤2替换为步骤3,则错误变为"路径myBundle_step3不存在".我试图清除缓存并运行php app/console asset:再次安装--symlink,但没有结果.
这是控制器对应的代码(真正的代码有点长,我不认为它是相关的,如果你这么认为,我可以把它反正:
namespace my\Bundle\Controller;
class IndividuController extends Controller
{
public function step2Action() {
Some code
}
public function step3Action($myParam) {
Some code
}
}
Run Code Online (Sandbox Code Playgroud)
相对于bundle的routing.yml配置文件:
myBundle_step2:
pattern: /step/2
defaults: {_controller: myBundle:Individu:step2}
options:
expose: true
myBundle_step3:
pattern: /step/3/{myParam}
defaults: {_controller: myBundle:Individu:step3}
options:
expose: true
Run Code Online (Sandbox Code Playgroud)
app/config/routing.yml文件:
fos_js_routing:
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"
myBundle:
resource: "@myBundle/Resources/config/routing.yml"
prefix: /
Run Code Online (Sandbox Code Playgroud)
布局的相关信息:
<!-- jQuery via Google + local fallback, see h5bp.com -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"> </script>
<script>window.jQuery || document.write('<script src="js/jquery-1.7.1.min.js"><\/script>')</script>
{% javascripts 'bootstrap/js/bootstrap.js'
'bundles/fosjsrouting/js/router.js'
'bundles/crrisuaps/js/suaps.js' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
<script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
php应用程序/控制台路由器的结果:debug(我只留下了相关的信息+我留下了未定义的变量通知以防万一,这是我添加这个库以来的通知,但是库仍然工作,我认为问题还不行来自这里:
Name Method Pattern
_assetic_55f0319 ANY /css/55f0319.css
_assetic_55f0319_0 ANY /css/55f0319_bootstrap_1.
css
_assetic_55f0319_1 ANY /css/55f0319_bootstrap-re
sponsive_2.css
_assetic_55f0319_2 ANY /css/55f0319_style_3.css
_assetic_3608a04 ANY /js/3608a04.js
_assetic_3608a04_0 ANY /js/3608a04_bootstrap_1.j
s
_assetic_3608a04_1 ANY /js/3608a04_router_2.js
_assetic_3608a04_2 ANY /js/3608a04_suaps_3.js
fos_js_routing_js ANY /js/routing.{_format}
myBundle_homepage ANY /
myBundle_inscription_etape1 ANY /inscription/etape/1
myBundle_inscription_etape2 ANY /inscription/etape/2
myBundle_inscription_etape3 ANY /inscription/etape/3/{dis
ciplineSelection}
Run Code Online (Sandbox Code Playgroud)
php app/console fos的结果:js-routing:debug(我删除了PHP通知但是它发生在我做的每个命令顺便说一下):
C:\wamp\www\suapsRepo\suaps>php app/console fos:js-routing:debug
[router] Current routes
Name Method Pattern
crrisuapsBundle_inscription_etape2 ANY /inscription/etape/2
crrisuapsBundle_inscription_etape3 ANY /inscription/etape/3/{disciplineSelect
ion}
Run Code Online (Sandbox Code Playgroud)
编辑:另外,不知道它是否相关,但当我尝试'php app/console fos:js-routing:debug myBundle_step2'我得到以下php错误:
[错误异常]警告:缺少Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand的参数3:outputRoute(),在第62行的C:\ symfonyDirectory\vendor\bundles\FOS\JsRoutingBundle\Command\RouterDebugExposedCommand.php中调用并在C:\ serverDirectory\vendor\symfony\src\Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand.php第98行
Aza*_*lvi 53
我也有这个问题.options.expose在路由配置上设置参数解决了它.
使用routing.yml
cart_edit:
pattern: /Cart/edit
defaults: { _controller: CartCartBundle:Default:cart_edit }
options:
expose: true
Run Code Online (Sandbox Code Playgroud)
my.js
var url = Routing.generate('cart_edit');
$.post(url, function(data) {
//do somthing
});
Run Code Online (Sandbox Code Playgroud)
根据需要改变.希望这能解决你的问题.
我有同样的问题,问题出在我的配置文件中.尝试检查:
# app/config/config.yml
fos_js_routing:
routes_to_expose: [ myBundle_step2, myBundle_step3, ... ]
Run Code Online (Sandbox Code Playgroud)
只是为了完整性:也可以使用注释 ( options={"expose"=true}),如文档中所述:
// src/AppBundle/Controller/DefaultController.php
/**
* @Route("/foo/{id}/bar", options={"expose"=true}, name="my_route_to_expose")
*/
public function indexAction($foo) {
// ...
}
Run Code Online (Sandbox Code Playgroud)
这也适用于控制器级别的路由集(来自我的一个控制器的示例):
/**
* Channel controller.
*
* @Route("account/{account}/todos", options={"expose"=true})
* @ParamConverter("account", class="AppBundle:Account", options={
* "repository_method" = "findOneById",
* "mapping": {"account": "id"},
* "map_method_signature" = true
* })
*/
class TodoListController extends Controller
{
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21994 次 |
| 最近记录: |