OSDN Git Service

指定Modelのデータない場合のWarning回避
authorCake <cake_67@users.sourceforge.jp>
Wed, 17 Feb 2010 04:49:39 +0000 (13:49 +0900)
committerCake <cake_67@users.sourceforge.jp>
Wed, 17 Feb 2010 04:49:39 +0000 (13:49 +0900)
app/models/app_model.php

index 1f68f28..c695938 100644 (file)
@@ -77,16 +77,18 @@ class AppModel extends Model {
        function beforeSave($options = array())
        {
                // $fieldsの設定でSanitize
-               foreach($this->data[$this->name] as $field => $value) {
-                       $this->data[$this->name][$field]  = $this->escapeByFields($field, $value);
+               if (isset($this->data[$this->name])) {
+                       foreach($this->data[$this->name] as $field => $value) {
+                               $this->data[$this->name][$field]  = $this->escapeByFields($field, $value);
+                       }
+                       // Sanitize(不正コード、SQL Injection)
+                       $this->data = Sanitize::clean(
+                               $this->data,
+                               array(
+                                       'encode' => false,
+                               )
+                       );
                }
-               // Sanitize(不正コード、SQL Injection)
-               $this->data = Sanitize::clean(
-                       $this->data,
-                       array(
-                               'encode' => false,
-                       )
-               );
 
                return parent::beforeSave($options);
        }