Take the 2-minute tour ×

I have a question about declaring $helper explicitly. This is sample code from CakePHP Book.

class PostsController extends AppController {
    public $helpers = array('Html', 'Form');


In my code, I didn't have that declaration at all, but my app is still working, I can save data via my web form, I can also using $this->Html->link().

Do I really need that declaration, any disadvantages if I didn't?

Thanks to all.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

The $helpers variable only needs to be declared when you are using a Helper other than 'HTML' and 'Form'. The core helpers 'Html' and 'Form' are loaded by default into the $helpers array, so the declaration is unnecessary if you only intend to use these.

If you want to add a custom helper, or use any other core helper, then you must declare the $helpers array. When you do this, you are overwriting the default helpers array, so you need to make sure to include the defaults again if you still intend to use them.

// Default. You do not need to declare this if you 
// only intend to use these helpers.
$helpers = array('HTML', 'Form'); 

// Add 'CustomHelper' to $helpers array. In this case
// HTML and Form must be declared.
$helpers = array('HTML', 'Form', 'Custom');
share|improve this answer
What if I need to use Session helper??? $helpers = array('Session'); or $helpers = array('Html', 'Form', 'Session'); Do I have to repeat declaring 'Html' and 'Form'??? –  Kongthap Oct 14 '12 at 14:27
Yes, you have to repeat Html and Form. So, if you wish to use the Session helper, the declaration should be $helper = array('Html', 'Form', 'Session'). –  Khior Oct 14 '12 at 15:22
add comment

Your Answer


