3

Having trouble geting cakephp to update a record.

Controller Code:

public function viewBenefit($id) {
    if ($this->request->is('post')) {
        $this->set('post', $this->request->data);
        $this->Benefit->id = $id;
        if ($this->Benefit->save($this->Benefit->data)) {
            $myVars['Sucsess'] = TRUE;
            $this->Session->setFlash('Updates Saved');
        } else {
            $myVars['NewID'] = 0;
            $myVars['Sucsess'] = False;
            $this->Session->setFlash('There was an error.');
        }
    }

    $this->Benefit->recursive = 2;
    $this->Benefit->id = $id;
    $this->set('benefit', $this->Benefit->read());
}

Relevant View Code:

<?php echo $this->Form->create('Benefit',array('action'=>'edit','url' => '#')); ?>
<?php echo $this->Form->input('id',array('type'=>'hidden')) . "\n"; ?>
<?php echo $this->Form->input('short_description',array('type'=>'textarea')) . "\n"; ?>
<?php echo $this->Form->end(); ?>

NOTE: The Form is sumbitted via JS

POST Data (via debug($post); )

array(
    'Benefit' => array(
        'id' => '1952e98e-f589-47d4-b458-11a1bd58ba3b',
        'short_description' => '<p>This is great sample insurance 321321</p>'
    )
)

SQL UPDATE statment:

UPDATE `c16memberdev`.`benefits` SET `modified` = '2012-12-04 10:45:16' WHERE `c16memberdev`.`benefits`.`id` = '1952e98e-f589-47d4-b458-11a1bd58ba3b'

As you can see the field "short_description" does not get added to the SQL statement, and therefore the data not added to the database. Thanks for your help.

1
  • where is $this->Benefit->data getting set? Dec 4, 2012 at 17:26

1 Answer 1

2

Try changing

$this->Benefit->save($this->Benefit->data)

to

$this->Benefit->save($this->request->data)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.