cakephp 2.0에서 saveAll로 문제를 해결하면 도움이 필요합니다. 나는 Datasheet, Datasheetsheading 및 Datasheetsvalues의 3 가지 모델을 가지고있다. 데이터 시트에서 마지막으로 삽입 한 ID를 모두 저장해야합니다.cakephp 2.0 saveAll with getlastid()
public function add_datasheet($id = null) {
$this->set('datasheetsheadings', $this->datasheetsheading->find('all', array('limit' => 0 .','. 9)));
$this->set('datasheetsheadings2', $this->datasheetsheading->find('all', array('limit' => 9 .','. 9)));
$this->set('id', $id);
if ($this->request->is('post')) {
if ($this->datasheet->save($this->request->data)) {
$this->datasheetsvalue->saveAll($this->request->data['datasheetsvalue']);
$this->Session->setFlash('Your Datasheet >> Lot: ' . $this->request->data['datasheetsvalue'][1]['value'] . ' << has been saved.');
$this->redirect(array('action' => 'Datasheets/' . $this->request->data['datasheet']['id_tbl_articles']));
} else {
$this->Session->setFlash('Unable to add your datasheet.');
}
}
}
내보기 :
<?php echo $this->Form->create('datasheet', array('action' => 'add_datasheet')); ?>
<fieldset>
<legend><?php echo __('Neues Datenblatt'); ?></legend>
<?php
$value_id = 0;
echo $this->Form->input('datasheet.comment', array('label' => 'Kommentar')) . '<hr>';
echo '<div style="width:300px;float:left;">';
foreach ($datasheetsheadings as $datasheetsheading) :
$value_id = $value_id +1;
echo $this->Form->input('datasheet.id_tbl_articles', array('type' => 'hidden', 'value' => $id));
echo $this->Form->input('datasheetsvalue.' . $value_id . '.id_tbl_articles', array('type' => 'hidden', 'value' => $id));
echo $this->Form->input('datasheetsvalue.' . $value_id . '.id_tbl_datasheets', array('type' => 'hidden'));
echo $this->Form->input('datasheetsvalue.' . $value_id . '.id_tbl_datasheetsheadings', array('type' => 'hidden', 'value' => $datasheetsheading['datasheetsheading']['id']));
echo __('<div style="width:140px;color:#FFF;float:left;">' . $datasheetsheading['datasheetsheading']['heading'] . '</div><div style="width:160px;color:#FFF;float:left;text-align:right;">');
echo $this->Form->input('datasheetsvalue.' . $value_id . '.print', array('type' => 'checkbox', 'label' => 'Im Datenblatt anzeigen', 'style' => 'color:#FFF;'));
echo '</div><div style="clear:left;"></div><div style="margin-top:-30px;">';
echo $this->Form->input('datasheetsvalue.' . $value_id . '.value', array('label' => ''));
echo '</div>';
endforeach;
echo '</div>';
echo '<div style="width:170px;float:left;"></div>';
echo '<div style="width:300px;float:left;">';
foreach ($datasheetsheadings2 as $datasheetsheading2) :
$value_id = $value_id +1;
echo $this->Form->input('datasheet.id_tbl_articles', array('type' => 'hidden', 'value' => $id));
echo $this->Form->input('datasheetsvalue.' . $value_id . '.id_tbl_articles', array('type' => 'hidden', 'value' => $id));
echo $this->Form->input('datasheetsvalue.' . $value_id . '.id_tbl_datasheets', array('type' => 'hidden'));
echo $this->Form->input('datasheetsvalue.' . $value_id . '.id_tbl_datasheetsheadings', array('type' => 'hidden', 'value' => $datasheetsheading2['datasheetsheading']['id']));
echo __('<div style="width:140px;color:#FFF;float:left;">' . $datasheetsheading2['datasheetsheading']['heading'] . '</div><div style="width:160px;color:#FFF;float:left;text-align:right;">');
echo $this->Form->input('datasheetsvalue.' . $value_id . '.print', array('type' => 'checkbox', 'label' => 'Im Datenblatt anzeigen', 'style' => 'color:#FFF;'));
echo '</div><div style="clear:left;"></div><div style="margin-top:-30px;">';
echo $this->Form->input('datasheetsvalue.' . $value_id . '.value', array('label' => ''));
echo '</div>';
endforeach;
echo '</div>';
echo '<div style="clear:left;"></div>';
echo $this->Form->end(__('Sichern'));
?>
</fieldset>
데이터 시트 테이블이 저장하는 데이터 시트에 저장하여 : id(auto_increment)
, id_tbl_articles
를, 나는 단지
내 컨트롤러 ... Datasheetsheading 읽기 comment
, created
, modified
. 이것은 완벽하게 작동합니다!
datasheetsvalue 테이블에서 값은 id(auto_increment)
, id_tbl_datasheetsheadings
, id_tbl_articles
, values
및 print
입니다. id_tbl_datasheets
에서만 NULL
이됩니다. 나는 $hasOne
, $hasMany
, $belongsTo
등으로 많은 시도를했습니다. id_tbl_datasheets
을 $this->datasheet->getlastid()
으로 설정하기도했습니다. 아무것도 작동하지 않습니다! 내가 saveAll
을 save
으로 바꿀 때 나는 올바른 값을 얻는다. 그래서 함수 saveAll
이 필요합니다.
Google은 과 함께 getLastId()
을 사용할 수 없다는 사실을 발견했습니다. 내가 뭘 써서 내 문제를 해결할 수 있을까?
누구나 답변 해 주셔서 감사합니다. 앤디.