我正在尝试创建一个简单的请求/接受函数。一个用户添加一个人 - 两个用户的用户名连同一个自动生成的 ID 添加到表中。现在,当其他用户检查他们的请求时,他们单击批准并将到期日期添加到记录中。当前发生的情况是,当用户单击接受并设置到期日期时,它会在关系表中创建一条新记录。
我的关系表的结构是
id
partyone
partytwo
active
expirydate
公共函数添加(){
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');
?>
我该如何编写代码以便它更新而不是创建一个带有到期日期的新行,请帮助我对此失去理智。