在阅读并应用所有有关下拉列表的建议答案后,我的下拉列表中仍然没有结果。我是新手,解决这个问题真的让我头疼。我有与 belongsTO Client_Group 表相关联的客户表。无论我对命名约定做了什么代码修改,我仍然无法将客户组的数据显示到我的下拉列表中。请帮忙!请帮忙!提前致谢
CREATE TABLE `clients` (
`id` int UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`client_group_id` int ,
`client_package_id` int ,
`client_account_id` int ,
`name` VARCHAR(40),
CREATE TABLE `client_groups` (
`id` INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(50),
INSERT INTO `client_groups` (`id`,`name`) VALUES (1,'Top Company Holdings');
INSERT INTO `client_groups` (`id`,`name`) VALUES (2,'Cadiz Group of Companies');
In CLient Model:
public $belongsTo = array(
'ClientGroup' => array(
'className' => 'ClientGroup',
'foreignKey' => 'client_group_id' ,
'fields' => 'name'
),
Client Group Model:
public $hasMany = array(
'Client' => array(
'className' => 'Client',
'foreignKey' => 'client_group_id',
'order' => 'Client.name DESC' )
在客户端控制器中: $clientgroups= $this->Client->ClientGroup->find('list',array( 'type'=>'select', 'fields'=> array('id', 'name'), 'order' => array('name' => 'ASC'))); $this->set(compact('clientgroups'));
In Client Add.ctp :
<?php echo $this->Form->input('client_group_id',array( 'option'=>$clientgroups ,
'type'=>'select', 'empty'=>'Select Group'));
?>