大家好,我正在尝试将表格中的信息加载到下拉框中。我正在尝试将包含 - 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 的条目