CakePHP中的时间重定向? [英] Time redirection in cakePHP ?

查看:131
本文介绍了CakePHP中的时间重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



如果我们要在5秒内重定向我们的页面,



有什么方法可以在cakephp的5秒内重定向网页?



如果是,请让我知道

解决方案

/cake/libs/controller/controller.php

  / ** 
* header()的便利和对象包装器方法。有用的做测试和
*断言特定的头已设置。
*
* @param string $ status正在设置的标题消息。
* @return void
* @access public
* /
函数头($ status){
header($ status);
}
...

这显示了Controller :: header )函数是一个简单的包装器,用于直接调用php函数header()。



http://api.cakephp.org/class/app-controller#method-AppControllerheader



所以 - 完成你想做的事情:



/app/controllers/examples_controller.php

 <?php 
class ExamplesController extends AppController
{
public $ name =Examples;
...
public function someAction(){
...
$ url = array('controller'=>'examples','action'=& someOtherAction');
$ this-> set('url',$ url);
$ this-> header(refresh:5; url ='。Router :: url($ url)。');
}
...
}
?>

我将url传递给视图,不要die()或exit()实际上希望渲染一个视图。示例:



/app/views/examples/some_action.ctp

 < p class ='notice'> 
<?php echo $ this-> Html-> link(你正被重定向到.Router :: url($ url)。在5秒内如果你不想等待点击here。,$ url); ?>
< / p>


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 cakephp ?

if yes please let me know

解决方案

/cake/libs/controller/controller.php

/**
 * Convenience and object wrapper method for header().  Useful when doing tests and
 * asserting that particular headers have been set.
 *
 * @param string $status The header message that is being set.
 * @return void
 * @access public
 */
    function header($status) {
        header($status);
    }
...

Which shows that the Controller::header( ) function is a simple wrapper for direct calls to the php function header( ).

http://api.cakephp.org/class/app-controller#method-AppControllerheader

So - to accomplish what you want to do:

/app/controllers/examples_controller.php

<?php
    class ExamplesController extends AppController
    {
        public $name = "Examples";
        ...
        public function someAction( ){
            ...
            $url = array( 'controller' => 'examples', 'action' => 'someOtherAction' );
            $this->set( 'url', $url );
            $this->header( "refresh:5; url='".Router::url( $url )."'" );
        }
        ...
    }
?>

I pass the url to the view and don't die( ) or exit( ) in case you actually wish to render a view. An example:

/app/views/examples/some_action.ctp

<p class='notice'>
    <?php echo $this->Html->link( "You are being redirected to ".Router::url( $url )." in 5 seconds. If you do not wish to wait click here.", $url ); ?>
</p>

这篇关于CakePHP中的时间重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆