I upgrading to v5 and have problem… in controller call component:
$cart = $this->Cart->read('order');
and i get error:
Table class for alias `Cart` could not be found.
In version 4 its works… i define components in AppController.php
$this->loadComponent('Cart');
Thanks for the advice
Can’t reproduce that.
What I did:
bin/cake bake component Cart
- Check that
$this->loadComponent('Cart');
is present inside the src/Controller/AppController.php
initialize method
- Add a method inside
src/Controller/Component/CartComponent.php
- Call it inside another controller via
$this->Cart->test();
Everything works as expected.
Also I am unable to find your specific error message
Table class for alias `Cart` could not be found.
in the source code.
So please post the whole stacktrace of your error.
I found where the problem is.
I do have CartController.php
public function initialize(): void
{
parent::initialize();
$this->Users = $this->fetchTable('Users');
}
So if I have the same name and component, it is probably looking for the name of the table in CartController.php
If I call the component in a controller other than CartController.php, it works.
if add $this->Cart = $this->loadComponent('Cart');
to initialize method to CartController.php
then its work…
public function initialize(): void
{
parent::initialize();
$this->Cart = $this->loadComponent('Cart');
$this->Users = $this->fetchTable('Users');
}