Time redirection in cakePHP ?

前端 未结 3 1888
囚心锁ツ
囚心锁ツ 2021-01-26 04:05

header(\"refresh:5; url=\'pagetoredirect.php\'\");

we can use this if we want to redirect our page in 5 second ,

is there any way to redirect page in 5 second in

3条回答
  •  暖寄归人
    2021-01-26 04:09

    Do not use $this->header in controller as it will be removed in 3.0. Use CakeResponse::header().

    here is working example for cakephp 2.8

    Controller:

    $url = array('controller' => 'pages', 'action' => 'index');
            $second = '5';
            if (!$sessionData) {
                return $this->redirect($url);
            }
            $this->Session->delete($bookingStr);
            $this->response->header("refresh:$second; url='" . Router::url($url) . "'");
            $this->set(compact('url', 'second'));
    

    View:

    Html->link( "You are being redirected to ".Router::url($url, TRUE)." in ".$second." seconds. If you do not wish to wait click here.", $url ); ?>

    Thank you.

提交回复
热议问题