Search code examples
cellhelpercakephp-3.0

How to call cell in helper in cakephp 3?


I need to call cell methods in my helper. I try this in my helper.

$cell = $this->cell('Inbox::expanded');

But it does not work. How can I do this?


Solution

  • There are two ways of doing this. The first one is to use the view instance inside the helper to render the cell:

    $cell = $this->_View->cell('Inbox::expanded');
    

    The other way is to add the CellTrait to your helper:

    class MyHelper extends Helper {
        use Cake\View\CellTrait;
    
        public function aMethod() {
            $cell = $this->cell('Inbox::expanded');
        }
    }