在我的应用程序的某些部分,我需要更新is_active
一些table
有很多字段的字段.仅更新此字段并避免所有其他字段的验证和要求的最佳方法是什么?
Man*_*dka 13
如果您只想更新特定行,请使用:
$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
}
Run Code Online (Sandbox Code Playgroud)
请参见此处(更新CakePHP3中的数据).
这将有效:
$users = TableRegistry::get('Users');
$query = $users->query();
$query->update()
->set(['is_active' => true])
->where(['id' => $id])
->execute();
Run Code Online (Sandbox Code Playgroud)
http://book.cakephp.org/3.0/en/orm/query-builder.html#updating-data
归档时间: |
|
查看次数: |
20423 次 |
最近记录: |