大家好我试图将信息从表格加载到下拉框中。我正在尝试从我的accounts_users表中加载account_id,其中包含-id,accounts_id,user_id到下拉框中。
account_id应仅显示来自accounts_users表中来自users table = user_id的id。目前,Dropbox仅从accounts_users表中加载id。
这是我的添加功能
function add() {
$this->set('title_for_layout', 'Please Enter Your Temaplate Details');
$this->set('stylesheet_used', 'style');
$this->set('image_used', 'eBOXLogo.jpg');
$accounts=$this->User->AccountsUser->find('list', array('conditions' => array('user_id' => $this->Auth->user('id'))));
debug($accounts);
if($this->request->is('post')){
$this->Template->create();
if ($this->Template->save($this->request->data)) {
$this->Session->setFlash('The template has been saved');
$this->redirect( array('controller' => 'Fields','action' => 'add'));
} else {
$this->Session->setFlash('The template could not be saved. Please, try again.');
}
}
$this->set('accounts', $accounts);
}
这是添加视图
<?php
echo $this->Form->create('Template', array('action'=>'add'));
echo $this->Form->input('name',array('label'=>'Template Name: '));
echo $this->Form->input('account_id',array('label'=>'Business: ', 'type' => 'select', 'options' => $accounts));
echo $this->Form->input('description',array('label'=>'Short Description Of Template: '));
echo $this->Form->end('Click Here To Submit Template');
?>
调试输出
app \ Controller \ TemplatesController.php(第20行) 阵列( (int)3 =&gt; '3' )
accounts_users表中的用户只有1个条目,id = 3,account_id = 10,user_id = 14
答案 0 :(得分:3)
$accounts=$this->User->AccountsUser->find('list', array('conditions' => array('user_id' => $this->Auth->user('id'))));
应该是:
$accounts=$this->User->AccountsUser->find('list', array('fields'=>array('id','account_id'),'conditions' => array('user_id' => $this->Auth->user('id'))));