0

我的控制器中有以下代码

$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”显示为一个简单的文本输入框。据我所知,两者的设置相同。那么为什么第二个输入没有形成选择框呢?

4

1 回答 1

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 属性大小写。

只有当你有一个名为“account_manager_id”的字段时它仍然会显示(在引用其他字段的主键时你应该根据约定)。

于 2013-08-03T03:56:55.973 回答