cakehp-form-helper:数据不保存


cakephp form helper: data not saving

我一直在玩CakePHP表单助手(cakehp-doc),并取得了一些成功。现在,我正在字符串中创建一个位于与表的模型无关的视图中的表单。我跟随医生,并将其放在我的视野中:

<?php echo $this->Form->create('ApplicationMemberships', array(
'url' => array('controller' => 'ApplicationMemberships', 'action' => 'add'))); ?>
<fieldset >
<?php
    echo $this->Form->input('chantier_id');
    echo $this->Form->input('application_id');
    echo $this->Form->input('ponderation',array('type' => 'number'));
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>

我把这个代码放在控制器中,以获得填充字段的数据:

$chantiers = $this->Chantier->find('list');
    $this->loadModel('Application');
    $applications = $this->Application->find('list');
    $this->set(compact('chantiers', 'applications'));

一切都很顺利:我有表格,我放了一些数据,然后我有一个闪光灯,说数据已经保存。问题:数据尚未添加到数据库中。


编辑:

以下是进行保存的代码:

    public function add() {
    if ($this->request->is('post')) {
        $this->ApplicationMembership->create();
        if ($this->ApplicationMembership->save($this->request->data)) {
            $this->Session->setFlash(__('The application membership has been saved'));
            //$this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The application membership could not be saved. Please, try again.'));
        }
    }
    $chantiers = $this->ApplicationMembership->Chantier->find('list');
    $applications = $this->ApplicationMembership->Application->find('list');
    $this->set(compact('chantiers', 'applications'));
}

错误是create('ApplicationMemberships')中的额外s。

根据Cakephp的约定,控制器应该是复数的,模型应该是单数的。因此,为了创建关联模型的实例,我应该写下:

create('ApplicationMembership')