我有一个'报告'功能,它提供了一个选项下拉列表和一个提交按钮。选择一个选项后,它会将该选项的ID传递给另一个名为“generatePatientInfo($ id = null)”的函数,然后生成一个csv。我的问题是在第一个数字后截断ID。像2,5,6,9这样的单个数字ID都按照它们应该的方式工作,但是如果ID是2044,它会将id截断为2并为id的选择提供选择的信息,而不是这是令人困惑的,我不知道如何解决它。以下是我的控制器和操作的视图代码。
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');
?>
答案 0 :(得分:0)
我将其缩小到我访问下拉信息的方式。在我的报告功能中,我正在错误地访问它。我必须将其更改为:$this->data['DrugCalls']['DrugList']
而不是$this->data['DrugCalls']['DrugList']['id']