This method takes an array, containing the details for each link. You can specify the text, filter tag and filter name for each. When a link is clicked your controller needs to detect these named parameters and only return the required data, this can be achieved with a simple switch statement.

Now when you go to the URL “www.example.com/controller/action/type:sent” for example, only records which have a status of 3 will be returned. All that is left to do now is use your new helper in the view.

The first part of this is an array to define the data for your filter links, then it is simply a case of using the helper to render the menu links. If you want to show more than just a vertical list, a little css is required (I borrowed the cakePHP default styles for pagination).

One thought on “Creating Filter Links in cakePHP”

Awesome article. Thanks for sharing. I did notice that line 20 in the helper did not work for me. I had to change it from:
$return .= ”.$this->Html->link($text,$link_url).”;
to:
$return .= ”.$this->Html->link($text,array(‘action’ => $this->params->action, $link[‘filter_tag’]=>$link[‘filter’], ‘full_base’ => false)).”;