<< Back
Calling a method / function from one controller in another controller cakephp 3 and cakephp 4
Calling a method / function from one controller in another controller cakephp 3 and cakephp 4
Calling a method / function from one controller in another controller cakephp 3 and cakephp 4
// load the model you need depending on the controller you need to use
$this->loadModel('User');
// use this in case you have tu instantiate a new entity
$user = $this->User->newEntity();
$user = $this->User->patchEntity($user, $this->request->data);
// using the controller on the fly, you could assign it to a var
// call the function you need
$result = (new UserController())->validateSomething($user);
// Test if result has something:
$this->Flash->success(__($result));
Published: 22nd January 2021 by stackoverflow