I am using symfony2 annotations and want to know how cascading works in this format.
Lets say I have:
/**
* @Route("/reviews/{slug}", name="reviewDetail")
* @Template()
*/
first, then I check to see if that pulls any data. If not, I do a redirect to the following controller using the following redirect:
return $this->redirect($this->generateUrl('reviewsDate', array('date' => $slug)), 301);
which should go to:
/**
* @Route("/reviews/{date}", name="reviewsDate", defaults={"date" = null})
* @Template()
*/
then check to see if that pulls any data and, if not, create a fallback to this using a redirect:
/**
* @Route("/reviews", name="reviews")
* @Template()
*/
When I run a redirect:
if ($ctx->getReview($slug)) {
$review = $ctx->getReview($slug);
} else {
return $this->redirect($this->generateUrl('reviewsDate', array('date' => $slug)), 301);
}
I get this error:
This webpage has a redirect loop
The actions are all stacked in the order of acceptance, so I would check for the slug first, then the date, then if no result, kick it to the main reviews page.
I can change the route to be more specific, which would work, but it seems not as user friendly. For instance, if I wanted to have these multiple routes:
reviews/my-review: shows the specific review reviews/2014: shows all reviews from the 2014 year
Is this the wrong way of of executing this functionality?
/**
* @Route("/reviews/{date}", name="reviewsDate", defaults={"date" = null})
* @Template()
*/
this is this same route as
/**
* @Route("/reviews", name="reviews")
* @Template()
*/
becouse you have default value null
for date
parameter so if you redirect to reviews
you are going to reviewDate
without parameter that causes endless loop.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.