0
对不起我的英语不好:(更新仅当变化来检测(自动)
我使用CakePHP的3框架,我想更新行在表格中的行(实体) (实体)在表中仅当的变化来检测(自动地)。
例如:
$id = 1;
// debug($this->request->data)
$this->request->data = ['id' => 1, 'name' => "My Name", 'content' => "My Content"];
// Inside the ArticlesController
$article = $this->Articles->get($id);
// debug($article)
object(Cake\ORM\Entity) {
'id' => (int) 1,
'name' => "My Name",
'content' => "My Content",
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Articles'
}
有没有d 。差分请求数据和之间原始数据所以我必须拒绝更新查询和返回警告检测到任何更改用户“! ?“
我有什么做的
感谢
没有脏方法不检测特定键的值是否已经改变:(如果你在'''$ this->'之后加了'''article'> name =“我的名字”'''''' , >文章 - > get($ id);'''你会得到''''[dirty]'=> ['name'=> true]'' –
是不是你想要的?您将能够检查'ArticlesEntity'是否更新'ArticlesController'中的实体。 – Jun
yes'''patchEntity'''会猜出**信号数据**和**请求数据** :)之间的区别 –