I'm using CakePHP 3.5 Url Helper to generate some Urls to be called using jQuery Ajax. I have the following 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);
});
And for some reason, my url is coming up like this
/tools/get-tools/param1=1&param2=5 (with & instead of &)
Because of that, when I use getQuery('param2') to get the value of query string parameter param2, I get null.
Any help please? Isn't this the way that I'm supposed to build url with query string parameters in CakePHP 3.5?
You can pass the second parameter to not escape the &
:
$this->Url->build([
"controller" => "tools",
"action" => "getTools",
"?" => [
"param1" => "PARAM1_PLACEHOLDER",
"param2" => "PARAM2_PLACEHOLDER"
]
], ['escape' => false]);