How to pass parameters to a Html Link Helper for CakePHP

If you are doing a link with a url, there not much what can be done, you would need to parse the named params array and attach to the link, but, if you are using the helper with an array specifying controller / action, the solution is simple:

$this->Html->link(‘My Link’, array_merge($this->params[‘named’], array(‘controller’ => ‘controller’, ‘action’ => ‘index’)));

This is very useful if you are passing named params between pages or if you want to keep some search criteria among pages (ex. when you have a pagination and a view and edit page, to return to the last landed page of the pagination).

Have fun (and maybe some cake :P)

Advertisements

About mcloide

Making things simpler, just check: http://www.mcloide.com View all posts by mcloide

2 responses to “How to pass parameters to a Html Link Helper for CakePHP

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: