euromark 12 years ago
parent
commit
fd0c334770
2 changed files with 12 additions and 3 deletions
  1. 9 0
      Model/Behavior/ResetBehavior.php
  2. 3 3
      Test/Case/Model/Behavior/ResetBehaviorTest.php

+ 9 - 0
Model/Behavior/ResetBehavior.php

@@ -22,6 +22,15 @@ App::uses('ModelBehavior', 'Model');
  *    $this->Model->Behaviors->load('Tools.Reset', array(...));
  *    $this->Model->resetRecords();
  *
+ * If you want to provide a callback function/method, you can either use object methods or
+ * static functions/methods:
+ *
+ *    'callback' => array($this, 'methodName')
+ *
+ * and
+ *
+ *    public function methodName($data, &$fields) {}
+ *
  * For tables with lots of records you might want to use a shell and the CLI to invoke the reset/update process.
  *
  * @author Mark Scherer

+ 3 - 3
Test/Case/Model/Behavior/ResetBehaviorTest.php

@@ -153,18 +153,18 @@ class MyComment extends AppModel {
 		return $data;
 	}
 
-	public function customStaticCallback($data, &$updateFields) {
+	public static function customStaticCallback($data, &$updateFields) {
 		$data['MyComment']['comment'] .= ' yyy';
 		$updateFields[] = 'some_other_field';
 		return $data;
 	}
 
-	public function fieldsCallback($data, &$updateFields) {
+	public static function fieldsCallback($data, &$updateFields) {
 		$data['MyComment']['comment'] = 'foo';
 		return $data;
 	}
 
-	public function fieldsCallbackAuto($data, &$updateFields) {
+	public static function fieldsCallbackAuto($data, &$updateFields) {
 		$data['MyComment']['comment'] = 'bar';
 		$updateFields[] = 'comment';
 		return $data;