【发布时间】:2017-02-09 08:40:10
【问题描述】:
我有一个创建多个数据库条目的路由。创建后,我想转发到获取这些条目并显示它们的路由。
这是获取/显示的路径:
/**
* @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,
));
}
这就是我从“数据库路由”重定向的方式:
return $this->redirectToRoute('appTourOverview', array(), 301); 但这会被缓存并且永远不会创建数据库条目...
我试过了:
我从“显示路径”中复制了所有内容,并让它立即返回数据库内容。
/* 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,
));
而不是重定向。不幸的是,这仅在刷新后有效? ($tours第一次为空)
有什么想法吗?
【问题讨论】:
-
您是否启用了例如 HTTP 缓存?还是你使用其他缓存?
-
尝试删除重定向的参数和状态码。默认状态码为 302,该代码可能会触发某些事件。
return $this->redirectToRoute('appTourOverview');