W
W
wolverine7772019-05-07 17:26:03
symfony
wolverine777, 2019-05-07 17:26:03

How to pass data to the same page (without page duplication)?

Hello,
I have the following picture:
I want to add a new page to the site - for this, at the first stage, you must enter the page text + title.
Further, after pressing the "save" button, it takes me to the next page where, according to. The title and text (which you just entered) appear in the fields.
Further, on this page I can change this text/title and then save it.
The problem is that every time I get to the "create a new page" or "change an already created page" page, symfony creates a new page for me instead of overwriting the information on the old one...
I tried not to flush() after the initial creation, then through Request $request to transfer the data to the controller that is responsible for "change the page", but in the dump of the title and text there is only null.

/**
     * @Route("site/page/new/{id}", name="add_new_page_site")
     */
    public function newPageTitle(Request $request,$id)

    {

        dump($id); /*die();*/

        $em = $this->getDoctrine()->getManager();

        $page = new geodePage();

        $form = $this->createForm(NewPageType::class, $page);

        $form->handleRequest($request);

        if($form->isSubmitted() and $form->isValid()) {

            $page->setIdSite($id);

            dump($page); /*die();*/
            $em->persist($page);
//            $em->flush();


            return $this->redirectToRoute('modif_page_site', [
                'id' => $page->getIdPage(),
                'idsite' => $id,
                'pageinfo'=>$page
            ]);


        }

        return $this->render('geode/site/pageSite.html.twig', [

            'post_form' => $form->createView(),
            'id' => $id,


        ]);

    }


    /**
     * @Route("site/page/edit/id_page/{id}", name="modif_page_site")
     */
    public function modif_page($id, Request $request){

        $titre = $request->query->get('titre');
        $texte = $request->query->get('texte');


        dump($titre, $texte); die;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim, 2019-05-07
@Matmode

In the modif_page method, you must load an object from the database by id and take data from it, and not from the request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question