how to save specific field in Cakephp
Asked Answered
P

1

5

here is my code

public function settings(){
$this->loadModel('Userinfo');

    $helpers = array('TimeZoneHelper');
    if($this->request->is('post')) {
        $id = $this->Auth->User('idUser');


 $data =  $this->request->data['Userinfo']['timezone'];
 $this->Userinfo->save($data,array(
     'conditions' => array('Userinfo.User_id' => $id))));

}

i have a field name timezone in my userinfo table .. which i want to update .. i dont know how can i specifically update the single field in Cakephp as i am new in Cakephp ..i am doing this but dont know why it isn't working ...well when i debug the $data .. the data is coming fine .. in database the datatype of timezone is "time"

Pandit answered 28/6, 2013 at 14:24 Comment(1)
You aren't showing a lot of effort here - There are 10s if not 100s of duplicate questions of this kind of thing - and it's also covered by the documentation and the blog tutorial. And it looks like you're just making code up (passing conditions to save? where have you seen that?).Genic
G
9

Set you models id:

$this->Userinfo->id = $id;

Then, use the savefield function to save a specific field:

$this->Userinfo->saveField('timezone', 'UTC');

Good luck further on cakePhp!

Guarded answered 28/6, 2013 at 14:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.