Question

I've baked a Plugin. The Controller in the Plugin works fine. Within the Controller I want to use the HtmlHelper within the Controller.

But... the Controller is complaining: $this->Html stays null.

The Controller in the Plugin contains: public $helpers = array('Html'); For debug purposes I have changed the location to $helpers to the AppController. In the folder Controller I've added a TestsController which extends from AppController. He has a working HtmlHelper.

My Plugin Controller extends also from the AppController:

Plugin Controllers:
- UserManagerAppController extends from AppController
- UsercomponentsController extends from UserManagerAppController

Normal Controller folder:
- AppController extends from Controller

Why doesn't UsercomponentsController contains a HtmlHelper?

Was it helpful?

Solution

Firstly, public $helpers = array('Html'); will not load the helper in your controller, it will load it in the view file rendered by your controller. You will be able to use the $this->Html reference in the view rendered, not any controller action. This is regardless of whether you try to load the Helper in a plugin controller or a normal one.

Check the package tree in the Cake Docs and read more on the differences between a Component and a Helper. You can use a Component in a Controller and a Helper in a View. You should not have the need to use the HtmlHelper (which assists with creating HTML form elements) in the controller. That would break the MVC paradigm.

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