Forms CAKEPHP2.3.1 HABMM编辑表单显示下拉框,而不是多选择框

Forms CAKEPHP2.3.1 HABMM编辑表单显示下拉框,而不是多选择框,forms,cakephp,edit,has-and-belongs-to-many,multi-select,Forms,Cakephp,Edit,Has And Belongs To Many,Multi Select,我在舞者和舞蹈之间有一种亲密的关系。除了在edit.ctp上编辑我的舞蹈外,CakePHP显示的是一个下拉框,而不是我所期望的多选框。让我疯狂的是,multi-select框以另一种方式与edit.ctp一起工作,用于编辑舞者!我不明白为什么它会以一种方式工作,而不是另一种方式 以下是我的舞蹈模型,定义了舞蹈和舞者之间的关系: public $belongsTo = array( 'User' => array( 'className' =&

我在舞者和舞蹈之间有一种亲密的关系。除了在edit.ctp上编辑我的舞蹈外,CakePHP显示的是一个下拉框,而不是我所期望的多选框。让我疯狂的是,multi-select框以另一种方式与edit.ctp一起工作,用于编辑舞者!我不明白为什么它会以一种方式工作,而不是另一种方式

以下是我的舞蹈模型,定义了舞蹈和舞者之间的关系:

    public $belongsTo = array(
        'User' => array(
            'className' => 'User',
            'foreignKey' => 'user_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );

/**
 * hasAndBelongsToMany associations
 *
 * @var array
 */
    public $hasAndBelongsToMany = array(
        'Dancer' => array(
            'className' => 'Dancer',
            'joinTable' => 'dancers_dances',
            'foreignKey' => 'dance_id',
            'associationForeignKey' => 'dancer_id',
            'unique' => 'keepExisting',
        )
    );
这是我的舞蹈控制器:

public function edit($id = null) {
    if (!$this->Dance->exists($id)) {
        throw new NotFoundException(__('Invalid dance'));
    }
    if ($this->request->is('post') || $this->request->is('put')) {
        if ($this->Dance->save($this->request->data)) {
            $this->Session->setFlash(__('The dance has been saved'));
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The dance could not be saved. Please, try again.'));
        }
    } else {
        $options = array('conditions' => array('Dance.' . $this->Dance->primaryKey => $id));
        $this->request->data = $this->Dance->find('first', $options);
    }
    $users = $this->Dance->User->find('list');
    $dancers = $this->Dance->Dancer->find('list');
    $this->set(compact('users', 'dancers'));
}
这是舞蹈视图的my edit.ctp

<div class="dances form">
<?php echo $this->Form->create('Dance'); ?>
    <fieldset>
        <legend><?php echo __('Edit Dance'); ?></legend>
    <?php
        echo $this->Form->input('id');
        echo $this->Form->input('dance_name');
        echo $this->Form->input('users_id');
        echo $this->Form->input('Dancers');
    ?>
    </fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
<div class="actions">
    <h3><?php echo __('Actions'); ?></h3>
    <ul>

        <li><?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $this->Form->value('Dance.id')), null, __('Are you sure you want to delete # %s?', $this->Form->value('Dance.id'))); ?></li>
        <li><?php echo $this->Html->link(__('List Dances'), array('action' => 'index')); ?></li>
        <li><?php echo $this->Html->link(__('List Dancers'), array('controller' => 'dancers', 'action' => 'index')); ?> </li>
        <li><?php echo $this->Html->link(__('New Dancers'), array('controller' => 'dancers', 'action' => 'add')); ?> </li>
    </ul>
</div>

我认为相关表格如下: 舞者, 舞者们跳舞, 跳舞

在dancers_dances表中,我有以下列: 身份证件 舞蹈家, 舞蹈演员

让我知道如果更多的信息将是有益的


提前感谢。

首先,您可以取消HABTM定义中的大多数设置,因为您已经在使用Cake约定

public $hasAndBelongsToMany = array(
    'Dancer' => array(
        'unique' => 'keepExisting',
    )
);
但问题在于表单中输入的名称,它应该是单数的,并以与之相关的模型命名

echo $this->Form->input('Dancer');
您可以在这里看到手册中的一些示例(在本节中查找“标记”示例):


首先,您可以去掉HABTM定义中的大多数设置,因为您已经在使用Cake约定

public $hasAndBelongsToMany = array(
    'Dancer' => array(
        'unique' => 'keepExisting',
    )
);
但问题在于表单中输入的名称,它应该是单数的,并以与之相关的模型命名

echo $this->Form->input('Dancer');
您可以在这里看到手册中的一些示例(在本节中查找“标记”示例):


可悲的是,我看不出有什么问题:(。请尝试将调试级别设置为高于0,同时确保edit.ctp确实位于它应该位于的路径中。我曾经在不同的位置浪费了数小时编辑同名文件。可悲的是,我看不出有任何问题:(.尝试将调试级别设置为高于0,同时确保edit.ctp确实位于它应该位于的路径中。我曾经在不同的位置浪费了数小时编辑同名文件。完美。你说得对表单中输入的名称必须是单数,与我的舞者模型相同。我今天学到了一些新东西。很高兴我能提供帮助。Pr像这样的问题可能会让人困惑,很容易被忽略,即使是有经验的CakePHP开发人员也是如此。祝你的项目好运,享受CakePHPPerfect。你是对的,表单中输入的名称必须是单数,与我的舞者模型相同。我今天学到了一些新东西。很高兴我能提供帮助。像这样的问题可能会让人困惑,而且很难解决很容易被忽略,即使是有经验的CakePHP开发人员。祝您的项目好运,享受CakePHP