我有一个“报告”功能,它提供了一个下拉选项和一个提交按钮。一旦选择了一个选项,它就会将该选项的 ID 传递给另一个名为“generatePatientInfo($id=null)”的函数,然后生成一个 csv。我的问题是 ID 在第一个数字之后被截断。单个数字 id 像 2,5,6,9 等都按照它们应该的方式工作,但是如果 ID 是 2044,它会将 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');
?>