2
我試圖將記錄保存到表中以及相關記錄。主表被稱爲引號,它有一個hasmany鏈接到表quote_items。 quote_items屬於報價CakePHP saveAll()函數問題
當我嘗試並保存它時將記錄保存在報價中,但不保存quote_items中的記錄 。
下面是我的報價添加功能
function add() {
if (!empty($this->data)) {
$this->Quote->create();
if ($this->Quote->saveAll($this->data)) {
$this->Session->setFlash(__('The Quote has been saved', true));
//$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Quote could not be saved. Please, try again.', true));
}
}
$this->Quote->recursive = 2;
$statuses = $this->Quote->Status->find('list');
$contacts = $this->Quote->Contact->find('list');
$this->set(compact('statuses', 'contacts'));
}
報價查看/形式設置
<?php echo $form->create('Quote', array('action' => 'add'));?>
<fieldset>
<legend><?php __('Add Quote');?></legend>
<?php
echo $form->input('Quote.name');
echo $form->input('Quote.revision');
echo $form->input('Quote.status_id');
echo $form->input('Quote.contact_id');
echo $form->input('quote_item.product_id');
echo $form->input('quote_item.name');
echo $form->input('quote_item.price');
echo $form->input('quote_item.description');
echo $form->input('Quote.totalcost');
?>
</fieldset>
<?php echo $form->end('Submit');?>
表單提交時返回數組
Array (
[quote] => Array (
[name] => Test
[revision] => 1
[status_id] => 1
[contact_id] => 1
[totalcost] => 123
)
[quote_item] => Array (
[product_id] => 1
[name] => test
[price] => 123
[description] => tes 1234
)
)
這似乎正是遵循在cakephp文檔中列出的是什麼,所以我無法弄清楚它爲什麼不能正常工作 - http://book.cakephp.org/view/84/Saving-Related-Model-Data-hasOne-hasMany-belongsTo
在此先感謝
使完美的感覺,當我打算修復它時,我來了如此接近,但我沒有采取需要擺脫下劃線。謝謝你:D – kwhohasamullet 2010-01-28 05:59:05