0

I have an ItemsController which extends AppController. To handle my site menu, I used a menuhelper. However, I saw in the documentation that you have to add your helpers in an array in your controller (AppController):

public $helpers = array('Form', 'Html', 'Menu');

The weird thing is that I forgot it and my menu worked anyway. Also, you always have to add Form and Html extra to the array because otherwise they don't work anymore. However, when I do something like this in my AppController, my form helpers still work:

public $helpers = array('Menu');

So it seems that whatever I do, it still works, but I don't get why and I don't like automatic "magic" :)

Is there something I am missing in the docs?

randomizer
  • 1,619
  • 3
  • 15
  • 31
  • show how you are using these helpers? – Anubhav Jan 20 '14 at 14:36
  • Well, in an add view I use "$this->Form->create('something')" which works, for the menu plugin, I call "$this->Menu->render($menu)" in my default layout, which also works. – randomizer Jan 21 '14 at 07:42

1 Answers1

1

Since 2.x you don't "need" to specify app or core helpers. Those are lazyloaded automatically.

You only need to specify plugin helpers manually.

That said I personally still always describe what helpers I use, just to be consistent with the plugin ones.

mark
  • 21,691
  • 3
  • 49
  • 71
  • Ok, so the docs aren't up to date? "You enable helpers in CakePHP by making a controller aware of them. Each controller has a $helpers property that lists the helpers to be made available in the view. To enable a helper in your view, add the name of the helper to the controller’s $helpers array:" It seems the docs aren't that clear on this issue. – randomizer Jan 21 '14 at 07:43
  • No, they are correct. As I mentioned it is good practice to still include them (even if it might work without it). Example: If you move one helper to a plugin then you would need to find all controllers where they might be needed and add it where otherwise you could just search for the occurrences and append the plugin prefix. – mark Jan 21 '14 at 11:20