luannx
luannx

Reputation: 11

Error update database in cakephp

I can not update databae Home vs field is: home_id, title, content: I Update data in Controller:

   $this->Home->home_id =1;
        $this->Home->set(array(
            'title'=>'sdfjksdf',
            'content'=>'lkjskldjfkljsdklj'
        ));
        $this->Home->save();

But it is insert the table home,not is update??? I try

    $this->Home->read(null, 1);

But it is error, because Column not found: 1054 Unknown column 'Home.id' in 'where clause'

Upvotes: 1

Views: 105

Answers (2)

Bogdan Kuštan
Bogdan Kuštan

Reputation: 5577

You need to inform CakePHP about your primary key

class Home extends AppModel {
    public $primaryKey = 'home_id';
    // ...
}

Upvotes: 1

Karthik Keyan
Karthik Keyan

Reputation: 426

In the cake php just we use 'ID' for primary keys name.

    $this->Home->id =1;
    $this->Home->set(array(
        'title'=>'sdfjksdf',
        'content'=>'lkjskldjfkljsdklj'
    ));
    $this->Home->save();

Try this.

Upvotes: 2

Related Questions