I'm not getting a phone related to a user in View edit()
. I can get the phone number in ver()
but not 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 it 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 app \ View \ Errors \ fatal_error.ctp
Thank you in advance.