我的控制器中有以下代码
$technicians = $this->Customer->Technician->find('list');
$account_managers = $this->Customer->Account_Manager->find('list');
$this->set(compact('technicians','account_managers'));
我的用户模型中有以下代码
public $hasMany = array(
'TicketComment' => array(
'className' => 'TicketComment',
'foreignKey' => 'user_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'CustomerTech' => array(
'className' => 'Customer',
'foreignKey' => 'technician'
),
'CustomerManager' => array(
'className' => 'Customer',
'foreignKey' => 'account_manager'
)
);
我的客户模型中有以下代码
public $belongsTo = array(
'Technician' => array(
'className' => 'User',
'foreignKey' => 'technician',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Account_Manager' => array(
'className' => 'User',
'foreignKey' => 'account_manager',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
我在视图中有以下代码
<div class="control-group">
<?php echo $this->Form->label('technician', 'Technician', array('class' => 'control-label'));?>
<div class="controls">
<?php echo $this->Form->input('technician', array('class' => 'span12')); ?>
</div><!-- .controls -->
</div><!-- .control-group -->
<div class="control-group">
<?php echo $this->Form->label('account_manager', 'Account Manager', array('class' => 'control-label'));?>
<div class="controls">
<?php echo $this->Form->input('account_manager', array('class' => 'span12')); ?>
</div><!-- .controls -->
</div><!-- .control-group -->
“技术人员”在我的视图中显示为正确的自动选择框,但“Account_Manager”显示为简单的文本输入框。据我所知,这两个设置相同。那么为什么第二个输入没有形成选择框?
答案 0 :(得分:0)
首先,它的AccountManager(没有_)代表模型的名称。
$accountmanagers = $this->Customer->Account_Manager->find('list');
$this->set(compact('technicians','account_managers'));
你不能说$ var并传递$ other并期望$ var在视图中可用:)
所以它应该(逻辑上)读取:
$accountManagers = $this->Customer->AccountManager->find('list');
$this->set(compact('technicians','accountManagers'));
还要注意camelBacked属性大小写。
如果你有一个名为&#34; account_manager_id&#34;的字段,它仍会显示出来。 (在引用其他字段的主键时,您应根据惯例)。