public function consultar_existencia($campo) {
if ($this->request->is('post')) {
$this->autoRender = false;
$this->layout = false;
$this->loadModel('Client');
$existe = $this->Client->find('count', array(
'conditions' => array($campo => $this->request->data('Field')['Data'])));
}
echo json_encode($existe);
}
Hi, I have this function in the controller, I'm going to use it to check if a data already exists in the database, the idea is to make some changes, but I've had some problems, I'm going to show you:
public function consultar_existencia($campo)
//field is for the field that is going to be compared in the DB, and the idea would also be to send the model to the one that is going to be consulted by adding something like $model
in the parameters, and in this line it would be loaded like this: $this->loadModel($model);
, and through there I think that We would go well, the problem comes in this line:
$existe = $this->Client->find('count', array(
'conditions' => array($campo => $this->request->data('Field')['Data'])));
since in that line a specific model is called, and my question is, is there any way to tell it to consult the currently loaded model? Something like
$this->getLoadModel()->find('count', array(
'conditions' => array($campo => $this->request->data('Field')['Data'])));
You can use the famous PHP variable Variables , in the documentation we found that variable properties exist and can be used in this way:
Which would be equivalent to doing this:
Since you said you already have the variable
$model
, you can do the following