0

I have a route that creates several database entries. After the creation I'd like to forward to a route that fetches those entries and displays them.

This is the route for fetching/displaying:

/**
 * @Route("/admin/app", name="appTourOverview")
 */
public function appTourOverviewAction(Request $request)
{

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

    /* Get Network for User */
    $network = $this->getUser()->getNetwork();

    $tours = $em->getRepository('AppBundle:Tour')->toursTodayByNetwork($network);

    return $this->render(':app:index.html.twig', array(
        'tour' => $tours,
        'imagePath' => Constants::IMAGE_PATH_DEV,
        'imagePathGreen' => Constants::IMAGE_PATH_DEV_GREEN,
        'imagePathYear' => Constants::IMAGE_PATH_DEV_YEAR,
    ));
}

and this is how I redirected from the "database route":

return $this->redirectToRoute('appTourOverview', array(), 301); but this gets cached and the database entries are never created...

I tried:

I copied everything from the "display route" and let it return the database stuff immediately.

/* Get Network for User */
    $network = $this->getUser()->getNetwork()->getId();

    $tours = $em->getRepository('AppBundle:Tour')->toursTodayByNetwork($network);

    return $this->render(':checker:index.html.twig', array(
        'tour' => $tours,
        'imagePath' => Constants::IMAGE_PATH_DEV,
        'imagePathGreen' => Constants::IMAGE_PATH_DEV_GREEN,
        'imagePathYear' => Constants::IMAGE_PATH_DEV_YEAR,
    ));

instead of the redirect. Unfortunately this only works after a refresh? ($tours is empty the first time)

Any ideas?

Community
  • 1
  • 1
PrimuS
  • 2,505
  • 6
  • 33
  • 66
  • Do you have enabled the HTTP Cache for example? Or do you use other caches? – René Höhle Feb 09 '17 at 08:50
  • Try to remove the parameter and status code for the redirect. The default status code is 302 and its possible that the code trigger some events. `return $this->redirectToRoute('appTourOverview');` – René Höhle Feb 09 '17 at 08:53

1 Answers1

2

the 301 redirect means he page was moved permanently and this information will be cached in your browser now. Please change that parameter to 302 or just remove (this is not necessary). Then, unfortunately you need to remove your browser's cache and the it should work.

302 means the redirect is temporary and browser won't cache it;

Piotr Pasich
  • 2,639
  • 2
  • 12
  • 14
  • I see, but it is not really "temporary" as it's expected behaviour? I used this now http://stackoverflow.com/a/16753260/1092632 but I think yours is good too, so thank you! – PrimuS Feb 09 '17 at 09:04
  • Temporary means - don't cache. nothing else :) – Piotr Pasich Feb 09 '17 at 09:08