2016-11-28 6 views
3

私はページインデックスからスライド1をスライド2に、次にスライド3を5秒ごとにリダイレクトしたいと思います。どうやってやるの。これまでのところ私はこの文書を使用して、これを試してください:http://symfony.com/doc/3.1/components/http_foundation.html#redirecting-the-usersymfonyは数秒おきにページからページへリダイレクトします

と、この質問から助け:私のビューに

/** 
* Bisdisp slide show preview action 
* 
* @param int $id 
* @Route("/bisdisp/{id}/slideshow/", name="_get_bisdisp_slideshow", requirements={"id" = "\d+"}) 
* @Template() 
*/ 
public function slideshowAction($id) 
{ 
    $power_plant = $this->getPowerPlant($id); 
    $response = new RedirectResponse($this->generateUrl('_get_bisdisp_slide1', [ 'id' => $id ])); 
    // $response->headers->set('Refresh', 5); 

    return $response; 
} 

/** 
* Slide 1 view 
* 
* @param int $id 
* @Route("/bisdisp/{id}/slideshow/slide1/", name="_get_bisdisp_slide1", requirements={"id" = "\d*"}) 
* @Template() 
*/ 
public function slide1Action($id) 
{ 
    $power_plant = $this->getPowerPlant($id); 
    $response = new RedirectResponse($this->generateUrl('_get_bisdisp_slide2', [ 'id' => $id ])); 
    // $response->headers->set('Refresh', 5); 

    return $response; 
} 

/** 
* Slide 2 view 
* 
* @param int $id 
* @Route("/bisdisp/{id}/slideshow/slide2/", name="_get_bisdisp_slide2", requirements={"id" = "\d*"}) 
* @Template() 
*/ 
public function slide2Action($id) 
{ 
    $power_plant = $this->getPowerPlant($id); 
    $response = new RedirectResponse($this->generateUrl('_get_bisdisp_slide3', [ 'id' => $id ])); 
    // $response->headers->set('Refresh', 5); 

    return $response; 
} 

:コントローラで

How to auto redirect a user in Symfony after a session time out?

<meta http-equiv="refresh" content="5"> 
{% block content %} 
<h3>Slide index</h3> 
{% endblock %} 

<meta http-equiv="refresh" content="5"> 
{% block content %} 
<h3>Slide 1</h3> 
{% endblock %} 

<meta http-equiv="refresh" content="5"> 
{% block content %} 
<h3>Slide 2</h3> 
{% endblock %} 
+1

ビューの中で 'HTTP-equiv'を削除し、あなたがSF http://stackoverflow.com/aでいくつかの期間の後にリダイレクトすることができますどのようにチェックを/ 18176467/1507546 – smarber

+0

Tnx、それは働いた! – sanof

答えて

1

まず最初にリフレッシュしてはならないページを表示するので、<meta http-equiv="refresh" content="5">を削除する必要があります。

そしてあなたはこれに似た何かを行うことができます:

private function getRedirectLater($url, $seconds=5) 
{ 
    $response = new Response; 
    $response->headers->set('Refresh', $seconds.'; url='. $url); 

    return $response; 
} 

/** 
* Bisdisp slide show preview action 
* 
* @param int $id 
* @Route("/bisdisp/{id}/slideshow/", name="_get_bisdisp_slideshow", requirements={"id" = "\d+"}) 
* @Template() 
*/ 
public function slideshowAction($id) 
{ 
    $power_plant = $this->getPowerPlant($id); 

    return $this->getRedirectLater($this->generateUrl('_get_bisdisp_slide1', [ 'id' => $id ])); 
} 

/** 
* Slide 1 view 
* 
* @param int $id 
* @Route("/bisdisp/{id}/slideshow/slide1/", name="_get_bisdisp_slide1", requirements={"id" = "\d*"}) 
* @Template() 
*/ 
public function slide1Action($id) 
{ 
    $power_plant = $this->getPowerPlant($id); 

    return $this->getRedirectLater($this->generateUrl('_get_bisdisp_slide2', [ 'id' => $id ])); 
} 

/** 
* Slide 2 view 
* 
* @param int $id 
* @Route("/bisdisp/{id}/slideshow/slide2/", name="_get_bisdisp_slide2", requirements={"id" = "\d*"}) 
* @Template() 
*/ 
public function slide2Action($id) 
{ 
    $power_plant = $this->getPowerPlant($id); 

    return $this->getRedirectLater($this->generateUrl('_get_bisdisp_slide3', [ 'id' => $id ])); 
} 
+0

はい、コメントしたようにしています。 Tnx! – sanof

関連する問題