1
I’m not getting a phone related to a user on View edit()
. I can get the phone number on ver()
but not in the edit()
.
Controller Patient:
public function edit($id = null) {
if (!$this->Patient->exists($id)) {
throw new NotFoundException(__('Invalid patient'));
}
if ($this->request->is(array('post', 'put'))) {
if ($this->Patient->saveall($this->request->data)) {
$this->Session->setFlash(__('The patient has been saved.'));
return $this->redirect(array('action' => '../patients/index'));
} else {
$this->Session->setFlash(__('The patient could not be saved. Please, try again.'));
}
} else {
$phone = $this->Phone->find('all');
$this->set(array('phone' => $phone));
$options = array('conditions' => array('Patient.' . $this->Patient->primaryKey => $id));
$this->request->data = $this->Patient->find('first', $options);
}
}
View:
<?php foreach ($phone as $phones): ?>
<?php
echo $this->Form->input('phone_number',array('label'=>'Telefone','value'=>$phones['Phone']['phone_number']),array('class'=>'form-control'));
?>
<?php endforeach; ?>
Model Patient:
public $hasMany = array('Phones'=> array('dependent' => true)) ;
}
Model Phone:
public $belongsTo = array('Patient');
}
When I try to access the page gives the following error:
Error: Call to a Member Function find() on null File: C: xampp htdocs cifisio app Controller Patientscontroller.php Line: 87
Notice: If you want to customize this error message, create View Errors fatal_error.ctp app
Thank you in advance.
Well it listed now, but when I modify the phone it does not update in the database.
– Felipe Henriques
That’s another question: the method to save is
saveAll()
, with the To uppercase. PHP is case-sensitive.– Paulo Rodrigues