Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to save specific field in Cakephp

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"

like image 747
hellosheikh Avatar asked Jun 28 '13 14:06

hellosheikh


1 Answers

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!

like image 80
jmc Avatar answered Oct 02 '22 03:10

jmc