9

What I am trying to achieve:

When user passes this:

/results?val=real&x=1&y=0

it should show:

/results/real.html?x=1&y=0

and from Action I should still be able to access $this->request->query['val'] which should be equal to real

What I have done so far?

I am using CakePHP 2.4

Router::parseExtensions('html');

Router::connect('/results/:val', 
            array('controller'=>'Post','action'=>'results',
'?' => array('val'=>'[A-Za-z0-9]-_ +','x'=>'[0-9]+','y'=>'[0-9]+')));

1 Answer 1

12
+50

Just define the route as like below in your routes.php file.

Router::connect(
    '/results/:val', 
    array(
        'controller' => 'Post',
        'action' => 'results',
    ), 
    array(
        'pass' => array('val')
    )
);

You can set the params like the below in order to generate the link in the way you want.

echo Router::url(array(
    'controller' => 'Post',
    'action' => 'results',
    'val' => 'real',
    'ext' => 'html',
    '?'  => array('x' => '1', 'y' => '0')
));

Which displays: results/real.html?x=1&y=0

Sign up to request clarification or add additional context in comments.

7 Comments

let me know if you have any query or concern keval sir @KarmicDice
Thanks @Anil however, I am posting a GET form... so do you advice that I take the parameters and then echo Router::url because URL will be formed automatically...
how can i make it complete, just advise me, so i can make it as completed
wait am playing around... hang in there... we have 6 days till it expires... so chill the f out...
ehm ... a very very very simple question: have you enabled the rewrite rules?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.