Database CakePHP函数不更新表
hi all当尝试更新我的数据库时,此函数不会从表中获取id,也不会更新表中的那一行。它还抛出了一个错误Database CakePHP函数不更新表,database,cakephp,Database,Cakephp,hi all当尝试更新我的数据库时,此函数不会从表中获取id,也不会更新表中的那一行。它还抛出了一个错误 $this->Relationship->id = $this->request->data['id']; 以下是整个功能 public function approve($id=null){ $this->Relationship->id = $id; if($this->request->is('get')
$this->Relationship->id = $this->request->data['id'];
以下是整个功能
public function approve($id=null){
$this->Relationship->id = $id;
if($this->request->is('get')){
$this->request->data=$this->Relationship->read();}
$this->Relationship->id = $this->request->data['id'];
if($this->Relationship->save($this->request->data)) {
$this->Session->setFlash('Your Relationship has been updated.');
$this->redirect(array('action' => 'request'));
} else {
$this->Session->setFlash('Unable to update your post.');
}
}
}
这是表格/视图
<?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');
?>
我想用这个函数做的是抓取一个id,并编辑该条目中的两个字段它应该是
$this->request->data['Relationship']['id']代码>如果表单设置正确。而且,你也可以这样做
$this->Relationship->create($this->request->data);
$this->Relationship->save()
我还必须将数据库中的tinyint从0=>1更改为0。我遇到的另一个问题是我的请求视图,它没有将id传递给approve函数。一旦我把代码改成这个,它就工作了
<?php foreach($Relationships as $relationship):?>
<tr>
<td align='center'><?php echo $relationship['Relationship']['partyone']; ?></td>
<td align='center'><?php echo $relationship['Relationship']['partytwo']; ?></td>
<td> </td>
<td><?php echo $this->Html->link($relationship['Relationship']['partyone'], array('action'=>'approve', $relationship['Relationship']['id'])); ;?>
</td>
</tr>
<?php endforeach; ?>
</table>
您能详细介绍一下我是如何设置表格的吗?
<?php foreach($Relationships as $relationship):?>
<tr>
<td align='center'><?php echo $relationship['Relationship']['partyone']; ?></td>
<td align='center'><?php echo $relationship['Relationship']['partytwo']; ?></td>
<td> </td>
<td><?php echo $this->Html->link($relationship['Relationship']['partyone'], array('action'=>'approve', $relationship['Relationship']['id'])); ;?>
</td>
</tr>
<?php endforeach; ?>
</table>