我在我的CakePHP應用程序有問題。我想從名爲選擇的表中檢索值我正確地檢索它。這些值在控制器部分中正確顯示。但在我看來,部分它僅顯示檢索到的最後的值...CakePHP的意見部分
我的代碼是:
function view($formid = null,$userid=null)//viewPage
{
$this->set('Forms',$this->Form->find('all',array('conditions'=>array('Form.id'=>$formid),'fields'=>array('Form.name'))));
$this->data['Form']['id']=$formid;
$viewfields=$this->Form->viewForms($this->data);
$this->set('viewfields',$viewfields);//retreives all the Attributes from the Form (like attribute_id,,label)
foreach($viewfields as $attributeid)://For each attribute id , i am checking if there is any choices in the Table Choices
$choices=$this->Choice->find('all',array('conditions'=>array('Choice.attribute_id'=>$attributeid['Attribute']['id'],'Choice.label'=>$attributeid['Attribute']['label']),'fields'=>array('Choice.choice','Choice.label')));
if(!empty($choices)){
$this->set('options',$choices);
foreach($choices as $c):
echo $c['Choice']['label'];
echo $c['Choice']['choice'];
endforeach;
}
endforeach;
}
上述工作以及在控制器的一部分,但如果我用:
foreach($options as $c):
echo $c['Choice']['label'];
echo $c['Choice']['choice'];
endforeach;
只顯示最後的值...爲什麼這樣呢?例如,我的屬性表中包含的條目,如:
id form_id label type sequence_no
1 1 Name text 1
2 1 age number 2
3 1 gender dropdown 3
4 1 email-id email 4
5 1 qualification dropdown 5
在我的選擇表:
id attribute_id label choice sequence
1 3 gender male 1
2 3 gender female 2
3 5 qualification BE 1
4 5 qualification ME 2
5 5 qualification MBA 3
在view.ctp
我只獲得資格的條目。這是爲什麼?
編輯:
我的看法頁面就像是:
<?php foreach ($viewfields as $r): ?>
if($r['Attribute']['type']=='text'||$r['Attribute']['type']=="email"){
echo $form->input($r['Attribute']['label'], array('id'=>$r['Attribute']['id'],'name'=>$r['Attribute']['label'],'type'=>'text','style' => 'width:' . $r['Attribute']['size'] . 'px'));
?><br>
}
else if($r['Attribute']['type']=='dropdown')
{
//here i want the Male and female for the label gender and for the label Qualification as BE ME MBA
echo $form->input($r['Attribute']['label'], array('id'=>$r['Attribute']['id'],'name'=>$r['Attribute']['label'],'options' => array(1,2,3,4,5)));
}
<?php endforeach; ?>
,因爲我已經使用12345
作爲選項的樣本..
elseif(dropdown)
環路內
像你說的我都試過的選項像
foreach($options as $c):
echo $c['Choice']['label'];
echo $c['Choice']['choice'];
echo $c[1]['Choice']['label'];
echo $c[1]['Choice']['choice'];
endforeach;
但我越來越錯誤和整個數組顯示,但我只想要性別選項的標籤性別和資格選項的資格。