Ejemplo n.º 1
0
 public function editAction($id, Request $request)
 {
     $id = (int) $id;
     $errors = [];
     if ($request->isPost()) {
         try {
             $date = new \DateTime();
             $id = Post::where(['id' => $id])->update(['title' => $request->post('title'), 'content' => $request->post('content'), 'date' => $date->format('Y-m-d H:i:s')]);
             return $this->redirect($this->generateRoute('home'), 'The data has been updated successfully');
         } catch (DatabaseException $e) {
             $errors[] = $e->getMessage();
         }
     }
     return $this->render('edit.html', ['post' => Post::find($id), 'action' => $this->generateRoute('edit_post', ['id' => $id]), 'errors' => $errors ?? null]);
 }