0

Is there a function to generate the corresponding URL given the request object?

For example, if the request params values are:

params => array(
        'plugin' => 'plugin',
        'controller' => 'foo',
        'action' => 'bar',
        'named' => array(),
        'pass' => array()
    )
    data => array()
    query => array(
                'key' => 'val'
        )
)

Then, generate the URL:

http://domain.com/plugin/foo/bar?key=val

3
  • 3
    You forgot the CakePHP version again. Also it's always helpful to explain the actual problem you are trying to solve, that way it's easier to figure a proper solution. That being said: Router::reverse($cakeRequestObject, true). Commented Oct 5, 2013 at 16:58
  • CakePHP version 2.3.4 Commented Oct 6, 2013 at 16:05
  • The Router::reverse worked. If you could post an answer so I could mark it :) Commented Oct 6, 2013 at 16:06

2 Answers 2

4

Whether this fits your needs depends of course, but generally Router::reverse() is able to build a URL from a request object:

Router::reverse($cakeRequestObject, true)

It's much like Router::url(), but it will do all the dirty work for you like including the query values and removing unnecessary parameters.

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

Comments

0

Just Use Router::reverse() like that way :

$url = Router::reverse($this->params);
echo $url;

Comments

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.