Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- public function action_add()
- {
- $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
- // if your form validation is okay than continue with everyhing else
- if ($val->run())
- {
- $article = Model_Article::forge();
- // Custom configuration for this upload
- $config = array(
- 'path' => DOCROOT.DS.'images',
- 'randomize' => true,
- 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'),
- );
- Upload::process($config);
- // if a valid file is passed than the fucntion will save, or if its not empty
- if (Upload::is_valid())
- {
- // save them according to the config
- Upload::save();
- //if you want to save to tha database lets grab the file name
- $value = Upload::get_files();
- foreach($value as $files) {
- print_r($files);
- }
- $article->filename = $value[0]['saved_as'];
- }
- $status = (Input::post('save_draft') ? 0 : 1);
- if ( ! $val->input('category_id'))
- {
- $category_id = null;
- }
- else
- {
- $category_id = $val->validated('category_id');
- }
- $article->user_id = $this->user_id;
- $article->category_id = $category_id;
- $article->title = $val->validated('title');
- $article->body = $val->validated('body');
- $article->published = $status;
- if ($article->save())
- {
- Session::set_flash('success', 'Article successfully added.');
- }
- else
- {
- Session::set_flash('error', 'Something went wrong, '.
- 'please try again!');
- }
- Response::redirect('articles/add');
- }
- $this->template->title = 'Add Article';
- $this->template->content = View::forge('articles/add')
- ->set('categories', Model_Category::find('all'), false)
- ->set('val', Validation::instance('add_article'), false);
- }
- /* End of file articles.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement