如何在 cakephp 3 中调用 helper 中的单元格?

How to call cell in helper in cakephp 3?

我需要在助手中调用单元格方法。我在我的助手中尝试这个。

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

但是不行。 我该怎么做?

有两种方法可以做到这一点。第一个是使用 helper 内部的视图实例来渲染单元格:

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

另一种方法是将 CellTrait 添加到您的助手:

class MyHelper extends Helper {
    use Cake\View\CellTrait;

    public function aMethod() {
        $cell = $this->cell('Inbox::expanded');
    }
}