Chris
Chris

Reputation: 644

Returning unknown variable in CakePHP

I'm trying to return an object in a model's view that goes an element and I can't figure out how to get my conditions out properly. Here's my controller:

    function view($id = null) {
    if (!$id) {
        $this->Session->setFlash(__('Invalid admission', true));
        $this->redirect(array('action' => 'index'));
    }
            $admission = $this->Admission->read(null, $id);

            **$_patient_id = 2;**
            $patientAdmissions = $this->Admission->getCurrentPatientAdmissions($_patient_id);

    $this->set(compact('admission', 'patientAdmissions'));
}

This view function is in the admissions_controller and shows a specific admission with $id. I want to display a div with all of this patient's admissions in it. My getCurrentPatientAdmissions looks like this:

    function getCurrentPatientAdmissions($_patient_id) {
      $params = array(
          'conditions' => array(
              'Admission.patient_id' => $_patient_id,
          ),
      );
      return $this->find('all', $params);
    }

Any ideas are much appreciated.

Upvotes: 0

Views: 43

Answers (1)

YonoRan
YonoRan

Reputation: 1728

Where are you placing the 'getCurrentPatientAdmissions' function? what file?

Why are you using the function 'getCurrentPatientAddmissions' instead of just running 'find'?

$patientAdmissions = $this->Admissions->find('all', array(
  'conditions' => array(
    'Admission.patient_id' => $admission['Patient']['id']
   )
  )
);

It seems like creating a function for something as simple as this is a bit over kill...

Doesn't the read function:

$admission = $this->Admission->read(null, $id);

already get a list of all the patients addmissions for you?

Upvotes: 1

Related Questions