Question

I'm using the CakeDC Tags plugin in my CakePHP project. I am using the TagCloudHelper to output a list of links but this helper isn't formatting the links the way I would like. Specifically the method _tagUrl($tag, $options) is generating links with named parameters instead of using the query string.

Instead of

$options['url'][$options['named']] = $tag[$options['tagModel']]['keyname'];

I get the desired behavior with the following change

$options['url']['?'][$options['named']] = $tag[$options['tagModel']]['keyname']; 

what is the best practice way of overriding this method? Do I make another class that extends TagCloudHelper? How then would I tell CakePHP to use my class instead of the plugin's?

Was it helpful?

Solution

I was able to override the helper with my own

// app/View/Helper/MyTagCloudHelper.php
App::uses('TagCloudHelper', 'Tags.View/Helper');

class MyTagCloudHelper extends TagCloudHelper {
    protected function _tagUrl($tag, $options) {
        $options['url']['?'][$options['named']] = $tag[$options['tagModel']]['keyname'];
        return $options['url'];
    }
}

Then in the controller

public $helpers = array('TagCloud' => array('className'=>'MyTagCloud'));

the className option let's you alias the name of the helper

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top