Hey guys, I'm trying to create a 'booking confirmed' link, that when clicked changes the table field 'confirmed' from 0 to 1.
so far I've got:
function admin_markAsCon开发者_开发技巧firmed($id = null) {
$this - > Booking - > id = $id;
if ($this - > Booking - > saveField('confirmed', 1)) {
$this - > Session - > setFlash('Booking Confirmed');
$this - > redirect(array('action' = > 'admin_index'));
}
}
But it's not working. All this does is insert a new row, instead of editing the row specified by $id.
How do I make this work? It seems so simple but I've been stuck for a good few hours on this.
You should use something like this...
$this->Post->id = 1;<br/> $this->Post->read();<br/> $this->Post->set('title', 'New title for the article');<br/> $this->Post->save();
Here is the link to the Cake book online
Try this:
// Update field to desired value
$data = array( 'someModel' => array( 'id' => $this->someModel->id, 'someField' => 'someInfo' ) );
// Save the changes
$this->someModel->save( $data, false, array('someField') );
精彩评论