cakephp - updating data without model with classRegistry -
i have table called user_tasks. not have model table , in totally unrelated controller have need update single field in user_tasks table.
this have tried far
$user = classregistry::init('user_tasks'); $conditions = "user_id = ". $user_id; $userrows = $user->find('first', array('conditions'=>$conditions)); $user->set(array( 'task' => $level )); $user->save();
however not $user->save(); , table never gets updated. can make work.
thanks
update:
in try / catch block, this
{"errorinfo":["hy000",1364,"field 'user_id' doesn't have default value"],"querystring":"insert `mytable`.`user_tasks` (`subscription`, `modified`, `created`) values ('latest', '2015-04-09 15:08:51', '2015-04-09 15:08:51')"}
ok figured out. have send user id
so
$user = classregistry::init('user_tasks');
$conditions = "user_id = ". $user_id; $userrows = $user->find('first', array('conditions'=>$conditions)); $user->set(array( 'task' => $level, 'user_id' => $user_id )); $user->save();
the above create new record. if updating record pass primary key. , if passing primary key, not need user_id etc. need fields in set need updated.