我正在嘗試創建一個簡單的請求/接受函數。用戶添加一個人 - 兩個用戶的用戶名都與自動生成的ID一起添加到表中。現在,當其他用戶檢查他們的請求時,他們會點擊批准並將有效日期添加到記錄中。目前發生的情況是,當用戶點擊接受並設置到期日期時,它會在關係表中創建一條新記錄。更新cakephp中的一行
我的關係表的結構是
id
partyone
partytwo
active
expirydate
公共函數add(){
if($this->request->is('post')){
$this->Relationship->create();
if ($this->Relationship->save($this->request->data))
{
$id=$this->Relationship->id;
$this->Session->setFlash('The relationship has been saved');
}
else { $this->Session->setFlash('The relationship could not be saved. Please, try again.'); }
}
}
public function approve(){
if($this->request->is('post')){
$this->Relationship->id;
$this->Relationship->getLastInsertID();
$this->Relationship->save($this->request->data);
$this->Session->setFlash('The information has been saved');}
else{
$this->Session->setFlash('The information couldnt be saved');}
}
}
這裏是我的批准觀點
<?php
echo $this->Form->create('Relationship', array('action'=>'approve'));
echo $this->Form->input('expirydate',array('label'=>'Expiry Date: ', 'class' => 'dateclass'));
echo $this->Form->end('Submit');
?>
這裏是我的外接觀點
<?php
echo $this->Form->create('Relationship', array('action'=>'add'));
echo $this->Form->input('partyone',array('label'=>'Enter your username: '));
echo $this->Form->input('partytwo',array('label'=>'Username of user: '));
echo "<br />";
echo $this->Form->end('Click here to add relationship');
?>
我該如何編碼,以便它更新並且不會創建帶有失效日期的新行,請幫助我對此失去理智。
這將不起作用,因爲'getLastInsertID()'將返回null,因爲還沒有插入任何內容。 – dhofstet