public function save_from_post()
{
if (count($_POST) > 0)
{
// Never save the PK; but load the record.
if (isset($_POST[$this->_primary_key]))
{
$this->find($_POST[$this->_primary_key]);
unset($_POST[$this->_primary_key]);
}
// Set each supplied attribute that exists in the model.
foreach ($this->_object as $key => $old_val)
{
// Only save if the key has been POST'd and the value has changed.
if (isset($_POST[$key]) && $_POST[$key] != $old_val)
{
$new_val = $_POST[$key];
$new_val = (is_string($new_val) && empty($new_val)) ? NULL : $new_val;
$this->$key = $new_val;
}
}
if ($this->check())
{
$this->save();
// Save files
foreach ($_FILES as $file)
{
if (empty($file['name'])) continue;
$dest_dir = DATAPATH.$this->db_name()
.DIRECTORY_SEPARATOR.$this->_table_name
.DIRECTORY_SEPARATOR.$this->id;
File::make_writable_dir($dest_dir);
File::copy_with_rename($file['tmp_name'], $dest_dir.DIRECTORY_SEPARATOR.$file['name']);
}
return TRUE;
}
}
return FALSE;
}
It looks like you're new here. If you want to get involved, click one of these buttons!