I know this post is a little outdated, and CakePHP versions have flourished since then. In the current version (2.1.x) of CakePHP and even in 1.3.x, if I'm not mistaken, you can get the current URL of the controller / view, for example:
$this->params['url'];
Although this method does NOT return parameters, it is convenient if you want to add parameters to the link when creating new URLs. For example, we have the current URL:
Projects / edit / 6
And we want to add a custom action of the c_action parameter with the remove_image value, you can use $this->params['url]; and combine it with an array of parameter pairs with key => parameters:
echo $this->Html->link('remove image', array_merge($this->params['url'], array('c_action' => 'remove_image'));
Using the method described above, we can add our custom parameters to the link and not call a long chain of parameters to create the URL, because $ this-> params ['url] only ever returns the URL of the control.
In the above example, we need to manually add the identifier 6 back to the URL, so that the final link layout will look like this:
echo $this->Html->link('remove image', array_merge($this->params['url'], array($id,'c_action' => 'remove_image'));
Where $ is is the identifier of the project, and you assigned it to the variable $ id at the controller level. The new URL will be as follows:
Projects / edit / 6 / c_action: remove_image
Sorry if this is not the least unrelated, but I came across this question when looking for a method to achieve the above and thought that others could benefit from it.
SimonDowdles Apr 02 '12 at 8:15 2012-04-02 08:15
source share