0

大家好,我正在尝试将表格中的信息加载到下拉框中。我正在尝试将包含 - id、accounts_id、user_id 的 accounts_users 表中的 account_id 加载到下拉框中。

只有当 users 表中的 id = accounts_users 表中的 user_id 时才会显示 account_id。目前,保管箱仅从 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 => '3')

accounts_users 表中的用户只有 1 个 id=3、account_id=10 和 user_id=14 的条目

4

1 回答 1

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'))));
于 2012-08-05T14:54:26.693 回答