Harley Alexander
Harley Alexander

Reputation: 127

update a single database field in cakephp - SHOULD BE SIMPLE

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_markAsConfirmed($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.

Upvotes: 2

Views: 5368

Answers (2)

Mark Fruhling
Mark Fruhling

Reputation: 606

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

Upvotes: 1

abbotto
abbotto

Reputation: 4339

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') ); 

Upvotes: 0

Related Questions