我正在尝试在我的网站中实现选择框。该选择框的选项在我的控制器中设置,如下所示
$tmp_user = $this->User->find('first',array('id'=>$this->Auth->user('id')));
$zip_info = $this->Zipcode->find('first',array('id'=>@$tmp_user['User']['zip_id']));
$region_admins = $this->AdminRegion->find('all',array('conditions'=>array('AdminRegion.region_id'=>@$zip_info['Zipcode']['region_id'])));
if(!empty($region_admins)){
foreach($region_admins as $radmn):
//pr($radmn);
$admin_user = $this->User->find('list',array('conditions'=>array('id'=>$radmn['AdminRegion']['user_id']),'fields'=>array('id','username')));
pr($admin_user);
$this->set('users',$admin_user);
endforeach;
当我从控制器打印时,我正在获得这样的价值
Array
(
[137] => governmentuser1
)
Array
(
[198] => testadmin
)
Array
(
[215] => adminregion
)
Array
(
[224] => testcompany1234
)
Array
(
[225] => testuser12345678
)
但只有最后一个值在选择框中设置.... 我哪里弄错了?
答案 0 :(得分:1)
这样的事情怎么样:
<?php
$tmp_user = $this->User->find('first', array(
'id' => $this->Auth->user('id')
));
$zip_info = $this->Zipcode->find('first', array(
'id' => @$tmp_user['User']['zip_id']
));
$region_admins = $this->AdminRegion->find('list', array(
'conditions' => array(
'AdminRegion.region_id' => @$zip_info['Zipcode']['region_id']
),
'fields' => array('AdminRegion.user_id', 'AdminRegion.user_id')
));
$admin_users = $this->User->find('list', array(
'conditions' => array(
'id' => $region_admins
),
'fields' => array(
'id','username'
)
));
?>
一些附注:
答案 1 :(得分:0)
我认为你错过了阵列:
$admin_user[] = $this->User->find('list',array('conditions'=>array('id'=>$radmn['AdminRegion']['user_id']),'fields'=>array('id','username')));
希望有所帮助