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'''會猜出**信號數據**和**請求數據** :)之間的區別 –