Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.20 KB | None | 0 0
  1. <?php      
  2.  
  3.     public function action_add()
  4.     {
  5.     $val = Model_Article::validate('add_article'); //<-- maybe its just me but i never saw any similar to this in fuelphp sorry about this if im wrong
  6.  
  7.     // if your form validation is okay than continue with everyhing else
  8.     if ($val->run())
  9.     {
  10.         $article = Model_Article::forge();
  11.         // Custom configuration for this upload
  12.         $config = array(
  13.             'path' => DOCROOT.DS.'images',
  14.             'randomize' => true,
  15.             'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'),
  16.         );
  17.  
  18.         Upload::process($config);
  19.  
  20.         // if a valid file is passed than the fucntion will save, or if its not empty
  21.         if (Upload::is_valid())
  22.         {
  23.             // save them according to the config
  24.             Upload::save();
  25.  
  26.            //if you want to save to tha database lets grab the file name
  27.             $value = Upload::get_files();  
  28.  
  29.             foreach($value as $files) {
  30.                print_r($files);
  31.             }
  32.             $article->filename = $value[0]['saved_as'];
  33.          }
  34.  
  35.         $status = (Input::post('save_draft') ? 0 : 1);
  36.  
  37.         if ( ! $val->input('category_id'))
  38.         {
  39.             $category_id = null;
  40.         }
  41.         else
  42.         {
  43.             $category_id = $val->validated('category_id');
  44.         }
  45.  
  46.              $article->user_id = $this->user_id;
  47.              $article->category_id = $category_id;
  48.              $article->title = $val->validated('title');
  49.              $article->body = $val->validated('body');
  50.              $article->published = $status;
  51.  
  52.  
  53.         if ($article->save())
  54.         {
  55.             Session::set_flash('success', 'Article successfully added.');
  56.         }
  57.         else
  58.         {
  59.             Session::set_flash('error', 'Something went wrong, '.
  60.                 'please try again!');
  61.         }
  62.  
  63.         Response::redirect('articles/add');
  64.     }
  65.  
  66.     $this->template->title = 'Add Article';
  67.     $this->template->content = View::forge('articles/add')
  68.         ->set('categories', Model_Category::find('all'), false)
  69.         ->set('val', Validation::instance('add_article'), false);
  70.     }
  71.  
  72. /* End of file articles.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement