"Correcting undefined index notice"

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6117 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-12-03 16:04:29 +00:00
parent 72164591fb
commit 13bd58587a

View file

@ -1079,13 +1079,13 @@ class Model extends Overloadable {
function save($data = null, $validate = true, $fieldList = array()) { function save($data = null, $validate = true, $fieldList = array()) {
$db =& ConnectionManager::getDataSource($this->useDbConfig); $db =& ConnectionManager::getDataSource($this->useDbConfig);
$_whitelist = $this->whitelist; $_whitelist = $this->whitelist;
$fields = array();
if (!empty($fieldList)) { if (!empty($fieldList)) {
$this->whitelist = $fieldList; $this->whitelist = $fieldList;
} elseif ($fieldList === null) { } elseif ($fieldList === null) {
$this->whitelist = array(); $this->whitelist = array();
} }
$this->set($data); $this->set($data);
if (empty($this->data)) { if (empty($this->data)) {
@ -1093,13 +1093,14 @@ class Model extends Overloadable {
} }
foreach (array('created', 'updated', 'modified') as $field) { foreach (array('created', 'updated', 'modified') as $field) {
if (array_key_exists($field, $this->data[$this->alias]) && $this->data[$this->alias][$field] === null) { if (isset($this->data[$this->alias]) && array_key_exists($field, $this->data[$this->alias]) && $this->data[$this->alias][$field] === null) {
unset($this->data[$this->alias][$field]); unset($this->data[$this->alias][$field]);
} }
} }
$exists = $this->exists(); $exists = $this->exists();
$fields = array_keys($this->data[$this->alias]); if (isset($this->data[$this->alias])) {
$fields = array_keys($this->data[$this->alias]);
}
if (!$exists && $this->hasField('created') && !in_array('created', $fields)) { if (!$exists && $this->hasField('created') && !in_array('created', $fields)) {
$colType = am(array('formatter' => 'date'), $db->columns[$this->getColumnType('created')]); $colType = am(array('formatter' => 'date'), $db->columns[$this->getColumnType('created')]);
@ -1134,6 +1135,7 @@ class Model extends Overloadable {
return false; return false;
} }
$fields = $values = array(); $fields = $values = array();
foreach ($this->data as $n => $v) { foreach ($this->data as $n => $v) {
if (isset($v[$n]) && in_array($n, array_keys($this->hasAndBelongsToMany))) { if (isset($v[$n]) && in_array($n, array_keys($this->hasAndBelongsToMany))) {
$joined[] = $v; $joined[] = $v;
@ -1168,7 +1170,6 @@ class Model extends Overloadable {
$success = false; $success = false;
} }
} else { } else {
foreach ($this->_schema as $field => $properties) { foreach ($this->_schema as $field => $properties) {
if ($this->primaryKey === $field) { if ($this->primaryKey === $field) {
if (empty($this->data[$this->alias][$this->primaryKey]) && $this->_schema[$field]['type'] === 'string' && $this->_schema[$field]['length'] === 36) { if (empty($this->data[$this->alias][$this->primaryKey]) && $this->_schema[$field]['type'] === 'string' && $this->_schema[$field]['length'] === 36) {