Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace CoderslabBundle\Controller;
- use CoderslabBundle\Entity\User;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
- use Symfony\Component\HttpFoundation\Response;
- class DefaultController extends Controller
- {
- /**
- * @Route("/createUser/")
- */
- public function createUserAction()
- {
- $user = new User();
- $user->setPassword('TajneHaslo2');
- $user->setLogin('Paweu');
- $em = $this->getDoctrine()->getEntityManager();
- $em->persist($user);
- $em->flush();
- return new Response('Tworzę życie!');
- }
- /**
- * @Route("/getUser/")
- */
- public function getUserAction()
- {
- $em = $this->getDoctrine()->getEntityManager();
- $userRepo = $em->getRepository('CoderslabBundle:User');
- $users = $userRepo->findOneBy([
- 'password' => 'qweqwe',
- 'login' => 'Paweu2'
- ]);
- dump($users);
- return new Response('Pobieram życie!');
- }
- /**
- * @Route("/editUser/{id}/")
- */
- public function editUserAction($id)
- {
- $em = $this->getDoctrine()->getEntityManager();
- $userRepo = $em->getRepository('CoderslabBundle:User');
- /** @var User $user */
- $user = $userRepo->find($id);
- $user->setPassword('Placki');
- $em->flush();
- return new Response('Edytuję życie!');
- }
- /**
- * @Route("/removeUser/{id}/")
- */
- public function removeUserAction($id)
- {
- $em = $this->getDoctrine()->getEntityManager();
- $userRepo = $em->getRepository('CoderslabBundle:User');
- /** @var User $user */
- $user = $userRepo->find($id);
- $em->remove($user);
- $em->flush();
- return new Response('Niszczę życie HeHe...!');
- }
- /**
- * @Route("/showAllArticles/")
- */
- public function showAllArticlesAction()
- {
- $articles = Article::GetAllArticles();
- return $this->render('CoderslabBundle:Article:showArticles.html.twig',
- [
- 'articles' => $articles
- ]
- );
- }
- /**
- * @Route("/showArticle/{id}/", name="show_article")
- */
- public function showArticleAction($id)
- {
- $article = Article::GetArticlebyId($id);
- return $this->render('CoderslabBundle:Article:showArticle.html.twig',
- [
- 'article' => $article
- ]
- );
- }
- /**
- * @Route("/test", name="test")
- */
- public function testAction()
- {
- return new Response('test');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement