仅更新Cakephp 3上的一个字段 [英] Update only one field on Cakephp 3
本文介绍了仅更新Cakephp 3上的一个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序的某些部分,我只需要更新某些表
中的字段 is_active
领域。仅更新此字段并避免所有其他字段的验证和要求的最佳方法是什么?
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?
推荐答案
要仅更新特定行,请使用以下命令:
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= abc@gmail.com; // other fields if necessary
if($users->save($user)){
// saved
} else {
// something went wrong
}
请参阅此处(在CakePHP3中更新数据)。
这篇关于仅更新Cakephp 3上的一个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文