/** * Action - blog/edit * edit post for current user * * @param int $id * @return string */ public function editAction($id) { $models = $this->app['models']; $request = $this->getRequest(); $locale = $this->getLocale(); $format = $locale == 'ru' ? 'd.m.Y' : 'm/d/Y'; $db = $this->app['db']; //-------------------- try { // Initialization $this->init(__CLASS__ . "/" . __FUNCTION__); // Get post for id $arrPost = $models->load('Post', 'getPost', $id); $date = new \DateTime($arrPost['created']); $arrPost['created'] = $date->format($format); // Set values $ormPost = new Post(); $ormPost->setValues($arrPost); // Create form $form = $this->createForm(new PostForm(), $ormPost, array('action' => "/blog/edit/{$id}")); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { // Save post $models->load('Post', 'editPost', array('edit_post' => $ormPost)); $this->addFlash('info_message', $this->trans('edited_this_message', array('{{ title }}' => $ormPost->getTitle()))); return $this->redirect("/account"); } // Show form return $this->showView(array('form' => $form->createView())); } catch (\Exception $exc) { return $this->showError($exc); } }