Advertisement
sanjiisan

Untitled

Sep 13th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. <?php
  2.  
  3. namespace CoderslabBundle\Controller;
  4.  
  5. use CoderslabBundle\Entity\User;
  6. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  8. use Symfony\Component\HttpFoundation\Response;
  9.  
  10. class DefaultController extends Controller
  11. {
  12. /**
  13. * @Route("/createUser/")
  14. */
  15. public function createUserAction()
  16. {
  17. $user = new User();
  18. $user->setPassword('TajneHaslo2');
  19. $user->setLogin('Paweu');
  20.  
  21. $em = $this->getDoctrine()->getEntityManager();
  22. $em->persist($user);
  23. $em->flush();
  24.  
  25. return new Response('Tworzę życie!');
  26. }
  27.  
  28. /**
  29. * @Route("/getUser/")
  30. */
  31. public function getUserAction()
  32. {
  33. $em = $this->getDoctrine()->getEntityManager();
  34.  
  35. $userRepo = $em->getRepository('CoderslabBundle:User');
  36.  
  37. $users = $userRepo->findOneBy([
  38. 'password' => 'qweqwe',
  39. 'login' => 'Paweu2'
  40. ]);
  41.  
  42. dump($users);
  43.  
  44. return new Response('Pobieram życie!');
  45. }
  46.  
  47.  
  48. /**
  49. * @Route("/editUser/{id}/")
  50. */
  51. public function editUserAction($id)
  52. {
  53. $em = $this->getDoctrine()->getEntityManager();
  54.  
  55. $userRepo = $em->getRepository('CoderslabBundle:User');
  56. /** @var User $user */
  57. $user = $userRepo->find($id);
  58. $user->setPassword('Placki');
  59.  
  60. $em->flush();
  61.  
  62. return new Response('Edytuję życie!');
  63. }
  64.  
  65.  
  66. /**
  67. * @Route("/removeUser/{id}/")
  68. */
  69. public function removeUserAction($id)
  70. {
  71. $em = $this->getDoctrine()->getEntityManager();
  72.  
  73. $userRepo = $em->getRepository('CoderslabBundle:User');
  74. /** @var User $user */
  75. $user = $userRepo->find($id);
  76.  
  77. $em->remove($user);
  78. $em->flush();
  79.  
  80. return new Response('Niszczę życie HeHe...!');
  81. }
  82.  
  83.  
  84. /**
  85. * @Route("/showAllArticles/")
  86. */
  87. public function showAllArticlesAction()
  88. {
  89. $articles = Article::GetAllArticles();
  90.  
  91. return $this->render('CoderslabBundle:Article:showArticles.html.twig',
  92. [
  93. 'articles' => $articles
  94. ]
  95. );
  96. }
  97.  
  98. /**
  99. * @Route("/showArticle/{id}/", name="show_article")
  100. */
  101. public function showArticleAction($id)
  102. {
  103. $article = Article::GetArticlebyId($id);
  104.  
  105. return $this->render('CoderslabBundle:Article:showArticle.html.twig',
  106. [
  107. 'article' => $article
  108. ]
  109. );
  110. }
  111.  
  112. /**
  113. * @Route("/test", name="test")
  114. */
  115. public function testAction()
  116. {
  117. return new Response('test');
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement