Using same Cell (with Helper) multiple times on same page results in fatal error (Cannot declare Helper class)

Hi Everyone,

Ik have a problem with using the same Cell multiple times on the same page. The simplified version is:

To start with, I have a PagesController with a View action

    public function view()
    {  }

So I have a View file in the Template/Pages/ folder, named ‘view.ctp’. The content of this view file is:

$section = $this->cell('Test', [1]);
echo $section;

I have a standard Cell, named TestCell (in the View/Cell folder) with this content:

namespace App\View\Cell;
use Cake\View\Cell;
class TestCell extends Cell
    protected $_validCellOptions = [];
    public function initialize()
    public function display($number)
        $calc = $number+1;

And a view file for the Cell, named ‘display.ctp’ (in the folder Template/Cell/Test) with this content:

echo   $this->Number->currency($calc, 'EUR') ;

When I now visit the page project/Pages/View, The page loads as it should and I see:

€ 2,00

PERFECT! So far so good! But now my problem:
I would like to do the following in the view.ctp file (of course: simplified):

$section = $this->cell('Test', [1]);
echo $section;
$section_2 = $this->cell('Test', [5]);
echo $section_2;

I had expected that would work, but: It gives me the following error:

Fatal error : Cannot declare class Cake\View\Helper\NumberHelper, because the name is already in use in C:\xampp\htdocs\lpos\src\View\Helper\NumberHelper.php on line 30

I get that the NumberHelper is loaded twice somehow, and that the Cell seems to to this, but: I don’t know how to get around it or fix the issue.
I hope someone can help me out! Thanks in advance.

It seems like you have a custom View Helper in src\View\Helper\NumberHelper.php

are you sure you only load that in your src/View/AppView.php like that?

    public function initialize(): void {
        $this->loadHelper( 'Number' );

Or how you you load your custom helper.

Hi Kevin,


You have pointed me in the right direction, and that helps me out A LOT. I have been struggeling with this for some time and simply did not know where to start/look (this is a bit above my head).
To be honest; I still do not completely understand it all, but you have now given me a starting point.
Again: thanks! and have a great day.