Exemple #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Blogpost();
     if (isset($_POST['Blogpost'])) {
         //var_dump("POSTED");
         $model->attributes = $_POST['Blogpost'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     } else {
         //var_dump("not POSTED");
     }
     $this->render('create', array('model' => $model));
 }
Exemple #2
0
 public function insertpost()
 {
     $this->data['title'] = "Blog - Insert";
     if (!$this->session->userdata('loggedin')) {
         $messages = array();
         $messages[] = 'Please <a href="' . base_url() . 'index.php/blog/login" title="Login">login</a> before attempting to create an entry.';
         $this->session->set_userdata('errors', $messages);
         redirect('/', 'view');
     } else {
         $post = new Blogpost();
         $u = new Bloguser();
         $u->get_by_username($this->session->userdata('username'));
         if (!$u->exists()) {
             $messages = array();
             $messages[] = 'Something extremely wonky has happened. You appear to be logged in but your username could not be found. Please email me at Josh.Kehn@gmail.com to resolve this issue.';
             $this->session->set_userdata('errors', $messages);
             redirect('/', 'blog');
         } else {
             $post->user_id = $u->id;
             $post->blog_id = $this->blog_id;
             $post->title = htmlentities($this->input->post('title'));
             $post->body = markdown($this->input->post('body'));
             $post->markdown = $this->input->post('body');
             //Process tags
             $tmp = explode(' ', $this->input->post('tags'));
             $tags = '';
             foreach ($tmp as $tag) {
                 $tags .= str_replace(',', '', $tag) . ' ';
             }
             $post->tags = trim($tags);
             $post->date = $this->input->post('date');
             if ($post->save()) {
                 $messages = array();
                 $messages[] = 'Successfully inserted ' . $post->title . '.';
                 $this->session->set_userdata('success', $messages);
                 redirect('/blog/view/' . $post->id, 'blog');
             } else {
                 $messages = array();
                 $messages[] = 'Error inserting post.';
                 $messages[] = $post->error->string;
                 $this->session->set_userdata('errors', $messages);
                 $this->data['post_title'] = $this->input->post('title');
                 $this->data['post_body'] = $this->input->post('body');
                 $this->load->view('insert_view', $this->data);
             }
         }
     }
 }