0

オプションのドロップダウンと送信ボタンを提供する「レポート」機能があります。オプションが選択されると、その選択の ID が「generatePatientInfo($id=null)」という別の関数に渡され、csv が生成されます。私の問題は、ID が最初の数字の後に切り捨てられることです。2、5、6、9 などの 1 桁の ID はすべて想定どおりに機能しますが、ID が 2044 の場合、ID が 2 に切り捨てられ、ID が 2 ではなく ID が 2 の選択肢の情報が表示されます。 2044. 困惑しており、修正方法がわかりません。以下は、アクションのコントローラーとビューのコードです。

 function report(){
$this->set('alldrugs', $this->Drug->find('list', array(
  //'cache' => 'drugList',
  //'cacheConfig' => 'sql',
  'fields' => array('id', 'generic'),
  'order' => 'Drug.generic',
  'recursive' => -1,
)));
if (!empty($this->data['DrugCalls'])) {
  $this->Session->setFlash(sprintf($this->data['DrugCalls']['DrugList']['id']));
  //$this->redirect(array('controller'=>'drugs','action'=>'generatePatientInfo',$this->data['DrugCalls']['DrugList']['id']));
  }
  }

  function generatePatientInfo($id=null) {
    $this->layout = 'ajax';
    // get drug info
    $drug = $this->Drug->read(
      array(
        'Drug.id', 'Drug.generic'
      ),
      $id
    );
    $this->set('drug',$drug);
    $patients = $this->Drug->query('SELECT patients.id, calls.id call_id, patients.first_name, patients.last_name, patients.phone, patients.email, calls.created '
      . 'FROM drugs, drug_lactation_links, lactation, calls, patients '
      . 'WHERE drugs.id = ' . $id . ' AND drugs.id = drug_lactation_links.drug_id AND '
      . 'drug_lactation_links.lactation_id = lactation.id AND lactation.call_id = calls.id AND calls.patient_id = patients.id '
      . 'UNION '
      . 'SELECT patients.id, calls.id call_id, patients.first_name, patients.last_name, patients.phone, patients.email, calls.created '
      . 'FROM drugs, drug_pregnancy_links, pregnancies, calls, patients '
      . 'WHERE drugs.id = ' . $id . ' AND drugs.id = drug_pregnancy_links.drug_id AND '
      . 'drug_pregnancy_links.pregnancy_id = pregnancies.id AND pregnancies.call_id = calls.id AND calls.patient_id = patients.id '
      . 'ORDER BY created DESC'
    );
    $this->set(compact('patients'));
    $this->set('title_for_layout', 'Patient contact information for ' . $drug['Drug']['generic']);
  }

ビュー:

<?php //report.ctp ?>
<div>

<?php echo $form->create('DrugCalls', array('url' => array('controller' => 'drugs', 'action' => 'report')));?>
<?php //echo $form->create('Patient Calls');?>
  <fieldset>
    <legend><?php printf('Calls for Generic Report'); ?></legend>
  <?php
    echo $form->input('DrugList', array('type' => 'select', 'id' => 'DrugList', 'label' => 'Select generic drug:',
      'empty' => 'Select', 'options' => $alldrugs)
    );
    echo '<br />NOTE: Select a drug above to generate a list of patients who called about it.' .
          '<br/>' . 'The report will need to be imported into Excel.';
    echo $form->end(__('Submit', true));
  ?>
  </fieldset>
</div>



<?php
//generate_patient_info.ctp
// add the header row
$header = array('First Name','Last Name','Phone Number','Email');

$csv->addRow(array('Enter Generic: ' . $drug['Drug']['generic']));
$csv->addRow(array('Drug ID: ' . $drug['Drug']['id']));
$csv->addRow($header);

// add all the data
foreach($patients as $patient) {
  $csv->addRow(array(
    $patient[0]['first_name'],
    $patient[0]['last_name'],
    $patient[0]['phone'],
    $patient[0]['email'],
  ));
}
$csv->addRow(array());

// render the CSV file
echo $csv->render('Patients-list.csv');
?>
4

1 に答える 1

0

I narrowed it down to the way I was accessing the dropdowns information. In my report function, I was accessing it incorrectly. I had to change it to: $this->data['DrugCalls']['DrugList'] Instead of $this->data['DrugCalls']['DrugList']['id']

于 2012-09-25T19:27:38.423 に答える