I’m trying to create a new record on a table called tutors. I named it that way in order to follow CakePHP conventions.
$codigoAlumnoNuevo = $this->Persona->id;
$tipoPersona = $this->request->data('TipoPersona'); # Just grabbing a POSTED value.
switch ($tipoPersona) {
case '0': # Es Tutor
$this->Tutor->create();
$this->Tutor->PersonaId = $codigoAlumnoNuevo;
$this->Tutor->save();
die("Saved record");
break;
case '1': # Es Alumno
$this->Tutor->create();
$this->Tutor->PersonaId = $codigoAlumnoNuevo;
$this->Tutor->save();
die("Saved record");
break;
case '2': # Es Coordinador de Programa
$this->Tutor->create();
$this->Tutor->PersonaId = $codigoAlumnoNuevo;
$this->Tutor->save();
die("Saved record");
break;
default:
break;
}
When trying to run this code, the following exception fires:
Call to a member function create() on a non-object
If I try this, I can see that $this->Tutor is NULL:
var_dump($this->Tutor);
But in the same controller, I can call $this->Persona->create(); just fine; $this->Persona is not null. Why is this? Why is Persona available but not Tutor?
Is it a naming thing?
Here’s my database model:

From your
PersonasControlleryou can only access thePersonamodel by default.If you want to run creates on the
Tutormodel, you need to addvar $uses = array('Persona','Tutor');to the beginning of yourPersonasController.phplike so: