Example #1
0
 public function actionEdit()
 {
     $id = $_GET['id'];
     // Get updating data:
     $updating = ModelArticle::getOneById($id);
     $this->isFound($updating);
     $view = new View(['article' => $updating, 'title' => $updating->title]);
     if ($this->isPost()) {
         $article = new ModelArticle();
         $article->id = $id;
         // fields cannot be empty!
         $success = $article->fill(['title' => $_POST['title'], 'content' => $_POST['content'], 'author_id' => $updating->author_id]);
         if ($success) {
             $article->save();
             header('Location: /article/one?id=' . $id);
             exit;
         } else {
             $_SESSION['error'] = 'Fields cannot be empty!';
             $view->article->content = $_POST['content'];
             $view->article->title = $_POST['title'];
         }
     }
     $view->displayPage('articles/edit');
 }