[英]passing more than one javascript parameter to a PHP file with twig
I want to pass three parameter to a PHP file with twig path()
.我想将三个参数传递给带有 twig
path()
的 PHP 文件。 I found a solution in this question .我在这个问题中找到了解决方案。 It works fine with one value, but with two values it puts
&
它使用一个值可以正常工作,但是使用两个值则将
&
instead of &
in the URL.而不是
&
在 URL 中。 this is the code I used:这是我使用的代码:
var route = "{{ path('dashboardTable', { 'data1': 'fistData', 'data2' : 'secondData})}}";
route = route.replace('firstData', D1);
route = route.replace('secondData', D2 );
window.location.href = route;
It sets the firstData
and socondData
and the URL will be this:它设置
firstData
和socondData
并且 URL 将是这样的:
http://localhost:8000/dashboard/table?data1=Low&data2=deactive
but because of the &
但由于
&
it's not working.它不工作。 how can I change
&
我怎样才能改变
&
to &
?到
&
?
the funny point is that if I put the amp;
有趣的是,如果我把
amp;
before data2
in my get request like below, it works fine!在我的 get 请求中的
data2
之前,如下所示,它工作正常!
$data2 = $_GET["amp;data2];
According to DaveCoast comment I added raw
in the code like below and it solved the problem .根据 DaveCoast 评论,我在如下代码中添加了
raw
并解决了问题。
var route = "{{ path('dashboardTable', { 'data1': 'fistData', 'data2' : 'secondData})|raw}}";
route = route.replace('firstData', D1);
route = route.replace('secondData', D2 );
window.location.href = route;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.