0
我一直在玩CakePHP表单助手(cakephp doc),并取得了一些成功。现在我正在创建一个与表格模型无关的表单。我跟着文档,并把在我看来:cakephp表单助手:数据不保存
<?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'));
}
您能否显示执行保存的代码? – Stian 2012-07-19 12:54:08
已添加代码。 qsdgfsdqfgsdgf – 2012-07-19 12:58:38
已解决。表格声明中的s。 – 2012-07-19 13:02:02