updateAll()に、beforeSave()とafterSave() のコールバックをトリガしたいです。
IDフィールドをアップデートしたいので、updateAll()を使っています。
save()が行っている感じで、beforeSave()とafterSave()を行うように、updateAll()をトリガしたいです。
CakePHP 1.3を使用しています。updateAll()のハックです。
lang
1function updateAll($fields, $conditions = true) { 2 $args = func_get_args(); 3 $oput = call_user_func_array(array('parent', 'updateAll'), $args); 4 if ($oput) { 5 $created = false; 6 $options_arr = array(); 7 $this->Behaviors->trigger($this, 'afterSave', array( 8 $created, 9 $options_arr, 10 )); 11 12 $this->afterSave($created); 13 $this->_clearCache(); 14 return true; 15 } 16 return false; 17}
下記はCakePHP 2.3で編集したコードです。
lang
1function updateAll($fields, $conditions = true) { 2 $args = func_get_args(); 3 $oput = call_user_func_array(array('parent', 'updateAll'), $args); 4 if ($oput) { 5 $created = false; 6 $options_arr = array(); 7 $event = new CakeEvent('Model.afterSave', $this, array($created, $options_arr)); 8 $this->getEventManager()->dispatch($event); 9 10 $this->afterSave($created); 11 $this->_clearCache(); 12 return true; 13 } 14 return false; 15}
もし、updateAllでbeforeSave()をコールしたいときはどうしたらいいのでしょうか?
わかる方がおられたらアドバイスお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。