0
good evening! I have 2 client tables and email ,when saving the client I need to save the email next to the email table, but I need to call the "save" function of the email controller. How do I do? Thank you all
0
good evening! I have 2 client tables and email ,when saving the client I need to save the email next to the email table, but I need to call the "save" function of the email controller. How do I do? Thank you all
0
To use a model from another controller, you can do the following:
public function add() {
...
Controller::loadModel('EmailModel');
$this->EmailModel->save(...);
}
0
At the beginning of the controller you have to put:
use Cake Controller Controller;
And in the method place: Controller::loadModel('model name_model');
After I put it the error disappeared.
Browser other questions tagged cakephp
You are not signed in. Login or sign up in order to post.
explains me, the Controller::loadModel('Emailmodel')?
– Horacio Neto
Within the method you use the model (example) "Emailmodel". For example, within your method
add()
– Danilo de Oliveira
paste and look like this: Controller::loadModel('Email'); $email="[email protected]"; $this->Email->save($email); but still error in "Controller:::loadModel('Email');" the error that shows is "Class 'App Controller Controller' not found" even trying to call "use App Controller Controller;" still gives error...
– Horacio Neto
I forgot to mention that this code should be placed inside the Controller, not in the Model. You’re doing this in the Controller, right?
– Danilo de Oliveira
yes , in the controller
– Horacio Neto
Just in case, add this to the beginning of your controller
App::uses('Controller', 'Controller');
– Danilo de Oliveira
put and appeared error "Class 'App Controller App' not found" my version of cake is that newer...makes a lot of difference?
– Horacio Neto
Possibly. Try using the function
$this->loadModel('Email')
, as in the documentation: https://book.cakephp.org/3.0/pt/controllers.html#loading-models-additional– Danilo de Oliveira