public function addCustomAction() { if ($this->_request->isPost()) { $addQuoteForm = new \App\Form\AddQuote(); if ($addQuoteForm->isValid($this->_request->getPost())) { $values = $addQuoteForm->getValues(); $newQuote = new \App\Entity\Quote(); $newQuote->setWording($values['quote']); $newQuote->setAuthor($values['name']); try { $this->_em->persist($newQuote); $this->_em->flush(); $this->indexQuote($newQuote); } catch (Exception $e) { $this->_redirect('/'); } } else { $addQuoteForm->buildBootstrapErrorDecorators(); } $data = $this->_em->getRepository("\\App\\Entity\\Quote")->findThemAll(); $this->view->data = $data; $this->_helper->viewRenderer('index'); } else { $this->_redirect('/'); } }
<?php /** * Created by JetBrains PhpStorm. * User: Michael * Date: 15.03.11 * Time: 18:32 * To change this template use File | Settings | File Templates. */ $newQuote = new \App\Entity\Quote(); $newQuote->setWording("Don’t let the past steal your present."); $newQuote->setAuthor("Cherralea Morgen"); $em->persist($newQuote); $em->flush();