CakePHP Tricks for manipulating URL in the view

Note: This blog is now over here
This week, I learnt many new tricks in CakePHP. Below are some of them
1. Get current URL in the view (Thanks to Grant Cox for this one) :
Use  Router::url(“”, true) to get current URL in the view. The second boolean parameter tells whether the path should be absolute or relative. Ideally Router::url(“”, true) should return an absolute URL of the current view, but it always returns the relative URL. So the hack to get the absolute URL is
$absolute_url  = FULL_BASE_URL + Router::url(“”, false);
if you use Router::url(“/”, true), it will return absolute url to your base web directory and this works as desired :p
2. Getting URL parameters in the view (Thanks to AD for this one):
You can get access to all the parameters in the view using $this->params. This will return you an array in this format
Array(
['pass'] => Array([0]=> [key1]=>v1 [key2] => v2……),
[controller]=>’controller_name’,
['action'] => ‘action_name’,

..
)
3. Passing an Array as second argument to $html->link (Again thanks to AD):
You can pass an array of parameters as the second parameter to $html->link. For instance, If I have an array that looks like this
$parameters = Array(
['controller'] =>’controller_name’,
['action'] =>’action_name’,
‘key1′=>v1,
‘key2′=>v2
);
To build a url from the above array, you can use $html->link($title, $parameters); This will return a string, “/controller_name/action_name/key1:v1/key2:v2/
I think to notice is the difference in array format that you get using $this->params and the one that you provide to $html->link. $this->params returns an array with a key “pass”, that contains all the key=>value pairs. Whereas, to build a url from an array, you need to specify all the key=>value at the same level at which you specify controller and action.
Enjoy