Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Acme\AdminBundle\Controller;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Acme\EntityBundle\Entity\Text;
- use Acme\AdminBundle\Form\Type\TextType;
- use Acme\EntityBundle\Entity\Translation\TextTranslation;
- use Symfony\Component\HttpFoundation\Request;
- class TextController extends Controller
- {
- public function showAllAction()
- {
- $request = $this->getRequest();
- $locale = $request->getLocale();
- echo $locale;
- $repository = $this->getDoctrine()
- ->getRepository('AcmeEntityBundle:Text');
- $query = $repository->createQueryBuilder('m')
- ->orderBy('m.id', 'DESC')
- ->getQuery();
- $texts = $query->getResult();
- if (!$texts) {
- throw $this->createNotFoundException(
- 'Nebyly nalezeny žádné články'
- );
- }
- return $this->render('AcmeAdminBundle:Text:showAll.html.php', array('texts' => $texts));
- }
- public function addTextAction(Request $request)
- {
- $text = new Text();
- $text->setTitle('');
- $text->setContent('');
- $form = $this->createForm(new TextType(), $text);
- $form->handleRequest($request);
- if ($form->isValid()) {
- /* nastaveni autora */
- $text->setAuthor($this->getUser()->getId());
- $em = $this->getDoctrine()->getManager();
- $em->persist($text);
- $em->flush();
- $this->get('session')->getFlashBag()->add(
- 'adminMessage', 'Text byl úspěšně přidán');
- return $this->redirect($this->generateUrl('acme_admin_text'));
- }
- return $this->render('AcmeAdminBundle:Text:add.html.php', array(
- 'form' => $form->createView(),
- ));
- }
- public function addTranslateAction($textId)
- {
- $text = $this->getDoctrine()
- ->getRepository('AcmeEntityBundle:Text')
- ->find($textId);
- $text->addTranslation(new TextTranslation('lt', 'title', 'Smt title lt'));
- $text->addTranslation(new TextTranslation('lt', 'content', 'Smth Content lt'));
- $em = $this->getDoctrine()->getManager();
- $em->persist($text);
- $em->flush();
- return $this->redirect($this->generateUrl('acme_admin_text'));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement