控制器:添加数据库排按钮CakePHP的
function add(){
if (!empty($this->data)) {
$qnote = $this->Qnote->save($this->data);
if (!empty($qnote)) {
$this->data['Step']['qnote_id'] = $this->Qnote->id;
$this->Qnote->Step->save($this->data);
}
$this->Session->setFlash('Your note has been saved.');
$this->redirect(array('action' => 'index'));
}
}
的形式。
<?php
$userID = Authsome::get('id');
echo $form->create('Qnote', array('action'=>'add'));
echo $form->input('Qnote.id', array('type' => 'hidden'));
echo $form->input('Qnote.user_id', array('value' => $userID, 'type' => 'hidden'));
echo $form->input('Qnote.subject');
echo $form->input('Qnote.body', array('rows' => '3'));
echo $form->input('Step.id', array('type' => 'hidden'));
echo $form->input('Step.user_id', array('value' => $userID, 'type' => 'hidden'));
echo $form->input('Step.body', array('rows' => '3'));
echo $form->end('Save Notes');
?>
此窗体在2个模型中添加数据。 模型1 = Qnote; 模型2 =步骤; 我可以将数据添加到模型。
我在想我可以添加一个按钮到表格 按钮可以让用户添加多个Step.data到Step模型。 有些人喜欢+1按钮。
基本上我想为每个Qnote添加多个步骤。
有人可以指出我在正确的方向我如何实现这一目标。
查看saveAll方法:http://book.cakephp.org/view/1031/Saving-Your-Data尽管您需要格式化数据 – JohnP 2011-05-05 11:56:40