第六點 - 謝謝。你的回答確實對我有幫助。
我改變了我的代碼中的一些變化,這裏是在EntriesController我admin_edit功能的一部分:
if ($this->request->is(array('post', 'put'))) {
//Load archive model and create object
$this->loadModel('Archive');
$this->Archive->create();
//Geting data of current entry (yes, i want to save old, non-edited entry data in archives)
$options = array('conditions' => array('Entry.' . $this->Entry->primaryKey => $id));
$current_entry = $this->Entry->find('first', $options);
//assignment to request data of archive
$this->request->data['Archive'] = $current_entry['Entry'];
//adding id for foregin key
$this->request->data['Archive']['entry_id'] = $this->request->data['Entry']['id'];
//adding reason from form data
$this->request->data['Archive']['reason'] = $this->request->data['Entry']['reason'];
//remove id, new entry of archive will be added
unset($this->request->data['Archive']['id']);
// save archive
if ($this->Archive->save($this->request->data)) {
$this->Session->setFlash(__('The archive has been saved.'));
} else {
$this->Session->setFlash(__('The archive could not be saved. Please, try again.'));
}
// save edited entry
if ($this->Entry->save($this->request->data)) {
$this->Session->setFlash(__('The entry has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The entry could not be saved. Please, try again.'));
}
}
現在我已經得到了我所需要的。我正在變老(編輯前)條目數據並將其保存爲存檔,具有原因。
你試過了什麼?請發佈您嘗試的解決方案,並告訴我們什麼不起作用 – StormeHawke