Example #1
0
 /**
  * Insert or update page files
  * Certain array structure need to be passed
  * 
  * array(
  * 	0 => array(
  * 		'id' 	=> If numeric and larger than 0, file will be updated. Otherwise file is considered new
  * 		'data'	=> Array of file data to insert
  * 	),
  * 	1 => array(
  * 		'id' 	=> If numeric and larger than 0, file will be updated. Otherwise file is considered new
  * 		'data'	=> Array of file data to insert
  * 	),
  * 	etc.
  * )
  * 
  * @param $files
  */
 public static function bind_files($files = array())
 {
     if (empty($files) || !is_array($files)) {
         return false;
     }
     foreach ($files as $key => $file) {
         $item = Model_File::forge($file['data']);
         if (is_numeric($file['id']) && $file['id'] > 0) {
             // Update existing file
             $item->set(array('id' => $file['id']));
             $item->is_new(false);
         }
         $item->save();
     }
 }
Example #2
0
File: files.php Project: xXLXx/ddc
 public function action_create()
 {
     if (Input::method() == 'POST') {
         $val = Model_File::validate('create');
         if ($val->run()) {
             $file = Model_File::forge(array('name' => Input::post('name'), 'file_url' => Input::post('file_url'), 'user_id' => Input::post('user_id')));
             if ($file and $file->save()) {
                 Session::set_flash('success', e('Added file #' . $file->id . '.'));
                 Response::redirect('site/files');
             } else {
                 Session::set_flash('error', e('Could not save file.'));
             }
         } else {
             Session::set_flash('error', $val->error());
         }
     }
     $this->template->title = "Files";
     $this->template->content = View::forge('site/files/create');
 }