I have a question about declaring $helper explicitly.
This is sample code from CakePHP Book.
<?php
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.
The
$helpersvariable 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$helpersarray, 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
$helpersarray. 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.