Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP+Symfony] dodanie rekordu
dopelganger
post
Post #1





Grupa: Zarejestrowani
Postów: 236
Pomógł: 0
Dołączył: 27.10.2012

Ostrzeżenie: (0%)
-----


Witam
nie wiem o co chodzi,
dodawanie rekordu działa ok, ALE nie zapisuje ID usera z sesji (FOSUserBundle).
Prosze o pomoc.

Kontroler:
  1. /**
  2.   * Creates a new Post entity.
  3.   *
  4.   * @Route("/", name="admin_posts_create")
  5.   * @Method("POST")
  6.   * @Template("BackendBundle:Post:new.html.twig")
  7.   */
  8. public function createAction(Request $request)
  9. {
  10. $entity = new Post();
  11. $form = $this->createCreateForm($entity);
  12. $form->handleRequest($request);
  13.  
  14. if ($form->isValid()) {
  15. $entity->setUserId($this->getUser()->getId());
  16. $em = $this->getDoctrine()->getManager();
  17. $em->persist($entity);
  18. $em->flush();
  19.  
  20. return $this->redirect($this->generateUrl('admin_posts_show', array('id' => $entity->getId())));
  21. }
  22.  
  23. return array(
  24. 'entity' => $entity,
  25. 'form' => $form->createView(),
  26. );
  27. }


Entity Post.php:

  1.  
  2. /**
  3.   * @ORM\Column(name="user_id", type="integer")
  4.   */
  5. private $user_id;
  6.  
  7. public function getUserId()
  8. {
  9. return $this->user_id;
  10. }
  11.  
  12. public function setUserId($user_id)
  13. {
  14. $this->user_id = $user_id;
  15. }


Ten post edytował dopelganger 4.02.2016, 15:28:43
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.12.2025 - 23:46