0

コントローラーに次のコードがあります

$technicians = $this->Customer->Technician->find('list');
$account_managers = $this->Customer->Account_Manager->find('list');
$this->set(compact('technicians','account_managers'));

User モデルに次のコードがあります

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 -->

「Technician」は適切な automagic 選択ボックスとしてビューに表示されますが、「Account_Manager」は単純なテキスト入力ボックスとして表示されます。私の知る限り、2つは同じように設定されています。では、なぜ 2 番目の入力が選択ボックスを形成しないのでしょうか?

4

1 に答える 1

0

まず、モデルの名前の AccountManager (no _)。

$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 に答える