Update only one field on Cakephp 3

Daniel Faria picture Daniel Faria · May 13, 2015 · Viewed 23k times · Source

In some part of my app I need to update only the field is_active of some table with a lot of fields. What is the best approach to update only this field and avoid the validations and requiriments of all other fields?

Answer

Manohar Khadka picture Manohar Khadka · Nov 13, 2016

And if you want to update particular row only , use this:

 $users= TableRegistry::get('Users');
 $user = $users->get($id); // Return article with id = $id (primary_key of row which need to get updated)
 $user->is_active = true;
 // $user->email= [email protected]; // other fields if necessary
 if($users->save($user)){
   // saved
 } else {
   // something went wrong
 }

See here (Updating data in CakePHP3).