klenwell information services : Paste20101003

CakePhp Routing Problem


Question

When an action handles a request to a url like: 'http://localhost/sandbox/destination/one%23two', should I expect $this->params['pass'][0] to be 'one#two'? In the event, it is just 'one'. (Cakephp 1.2)

Compare: http://www.google.com/#sclient=psy&num=10&hl=en&q=one%23two

Answer

The difference is that the google url has the hash in the query string (though they do now put that weird one where I'd expect a ?). I guess that's the difference. I wanted to allow it as a parameter through the url path. But it appears that's not possible, at least without a bit of cumbersome manual encoding and decoding.

Sample Code

simple controller (sandbox_controller.php) action
    function test()
    {
        $this->redirect(sprintf('/sandbox/destination/%s',
          urlencode('one#two')));
    }

    function destination()
    {
        pr($this->params);
    }


Browse to http://localhost/sandbox/test
End up here: http://localhost/sandbox/destination/one%23two

Output
Array
(
    [pass] => Array
        (
            [0] => one
        )

    [named] => Array
        (
        )

    [controller] => sandbox
    [action] => destination
    [plugin] =>
    [form] => Array
        (
        )

    [url] => Array
        (
            [url] => sandbox/destination/one
        )

)