If you write a helper you sometimes want to access functions of another helper. Let’s say you want to use the link() function of the HtmlHelper in your own helper. First you have to define the helper you want to use in the $helpers array:
class TestHelper extends AppHelper {
var $helpers = array('Html');
}
You may expect that you could use the helper with $html->link(), but that leads to an “undefined variable” error (I blunder into this trap almost every time I use this functionality *g*). Instead you have to use $this->Html->link() as shown in the example:
class TestHelper extends AppHelper {
var $helpers = array('Html');
function getTheLink() {
return $this->Html->link('The link', '/');
}
}

Hey thanks so much, I was using it without $this!
@Kym: You are welcome!
Thanks for posting this. It was exactly what I was looking for as I wasn’t quite sure how to access a helper from within a helper.
@Dan: I’m glad this article was helpful for you, and happy baking!
Hi, thanks for the article!
Is it possible to request a helper inside a helper’s method? Same as you would do in a controller’s action instead of the entire controller?
function getTheLink() {
var $helpers[] = ‘Html’;
return $this->Html->link(‘The link’, ‘/’);
}
@enrique: Thanks for your comment!
You could use something like:
And depending on the helper you want to load you have to do some initializations.
However, if possible, I would avoid this approach and use what I described in the article ;-)
thanks for this, so simple but took ages to get this info, c’est la cake
@brendan: You are welcome :)
Thanks, I’ve been trying to figure out how to do this for a few hours already.
@Bill: You are welcome :)
I tried what @enrique mentioned, since that method works on controllers just fine. But the only way I can get it to work is by using the original method mentioned in this post, which is by importing the helper to the entire helper class.
@Rodrigo: To avoid loading the helper for the entire helper class, you can use the approach I posted as answer to @enrique’s comment.