Cakephp 3查询字符串构建编码&

时间:2018-03-22 23:07:36

标签: php cakephp cakephp-3.4

我正在使用CakePHP 3.5 Url Helper生成一些使用jQuery Ajax调用的Urls。我有以下Ajax:

$(".container").on("change", "#select_box", function(){
                url = '<?= $this->Url->build(["controller" => "tools", "action" => "getTools", "?" => ["param1" => "PARAM1_PLACEHOLDER", "param2" => "PARAM2_PLACEHOLDER"]]); ?>';

            url = url.replace("PARAM1_PLACEHOLDER", $(this).val()).replace("PARAM2_PLACEHOLDER", 5);

            $("#tools").load(url);
        });

出于某种原因,我的网址就像这样出现了

/tools/get-tools/param1=1&amp;param2=5 (with &amp; instead of &)

因此,当我使用getQuery('param2')获取查询字符串参数param2的值时,我得到null。

请帮忙吗?这不是我应该用CakePHP 3.5中的查询字符串参数构建url的方式吗?

1 个答案:

答案 0 :(得分:2)

您可以传递第二个参数以不转义&

$this->Url->build([
    "controller" => "tools",
    "action" => "getTools",
    "?" => [
        "param1" => "PARAM1_PLACEHOLDER",
        "param2" => "PARAM2_PLACEHOLDER"
    ]
], ['escape' => false]);