Question

In CakePHP 2.4, how do I safely pass my view query string to a custom URL query string?

Essentially, when visiting the view at posts/map?param1=1&param2=2, I need the view to echo /posts/points.json?param1=1&param2=2.

EDIT: Hacky workaround for HtmlHelper munging & into &

    echo str_replace("&", "&", $this->Html->url(array(
        'controller' => 'posts',
        'action' => 'points',
        'ext' => 'json',
        '?' => $this->request->query
        )));
Was it helpful?

Solution

Please read passed-named-or-query-string-params.

You should use query strings in CakePHP2.x Those are the correct form of passing values between urls via GET. They also play nicely with extensions.

Also, your action name is wrong. You should separate it into "action" and "ext":

array(
    'controller' => 'posts',
    'action' => 'points',
    'ext' => 'json',
    '?' => array('param1' => 1, ...)
),
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top