cakephp下拉框和数组

时间:2012-09-23 11:57:42

标签: arrays cakephp find

大家好我在视图上有一个下拉框。我有一个find语句返回一个模板列表,当我调试find时,它打印出正确的template.id和template.name列表但是当我提交表单时,它会携带它在列表中的数字,例如如果我在列表中选择第5个模板,则会保存template_id = 5而不是实际的模板ID号。

//Retrieve Account Id of current User       
$accountid=$this->Auth->user('account_id');

//conditions for template arrays
$conditions=
array('AND' => array(
    array('Template.account_id' => $accountid),
    array('Template.active' => 1)
));

//An array of all Templates belonging to the current User's Account
$templates=$this->Template->find('list', array(
    'conditions' => $conditions));

当我调试$ templates时,我打印出来

array(
    (int) 1 => 'Consulting- Bus',
    (int) 2 => 'Consulting- Pers',
    (int) 7 => 'ClientEdge',
    (int) 8 => '11111',
    (int) 9 => 'testSUn',
    (int) 10 => 'Test Bruce Review',
    (int) 11 => 'Test Bruce 3 = Final'

当我选择“测试布鲁斯评论”并点击提交并调试它打印出来的值为'6'时,下拉框中的第6项当我希望它在我调试时打印出10。

这是与此下拉框相关的表单中的代码段

<tr><td><?php echo "Template: "?></td>
<td><?php echo $this->Form->input('template_id', array('label'=>false,'type'=>'select','options'=>$templates));?></td></tr>

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我在合并导致模板死亡的数组时遇到了问题。