Errors when visiting `/error` url
asgraf opened this issue · comments
Steps to reproduce:
- Create new cakephp application from cakephp/app
- Install Crud plugin
- Visit https://localhost/error (I assume you are working on a localhost domain)
You will get following errors:
notice: Undefined property: ErrorController::$Crud in /application/vendor/friendsofcake/crud/src/Controller/ControllerTrait.php on line 97
error: [TypeError] method_exists(): Argument #1 ($object_or_class) must be of type object|string, null given in /application/vendor/friendsofcake/crud/src/Controller/ControllerTrait.php on line 97
Either add a parent::initialize()
call to your ErrorController::initialize()
or include the ControllerTrait
for the individual controllers instead of AppController
.
From my experience adding parent::initialize()
call in ErrorController::initialize()
is bad idea because it can sometimes cause infinite error loops in some cases.
My project has 90+ controllers & tables. Manually adding ControllerTrait
to each of them (except ErrorController
) would be lot of work that could be avoided by simple if statements in ControllerTrait
itself
Add $this->dispatchComponents['Crud'] = false
in your ErrorController::initialize()
.
It worked. I suggest adding this to installation manual.