最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - yii - how to redirect after 10 seconds - Stack Overflow

programmeradmin1浏览0评论

I am new to the yii framework, and I can't see to find any information or forums about how to redirect after 10 seconds has pass on a page. for example after resetting your password, I would like to redirect to the login page but only once its been 10 second to allow the user to see the message display on the page.

I am new to the yii framework, and I can't see to find any information or forums about how to redirect after 10 seconds has pass on a page. for example after resetting your password, I would like to redirect to the login page but only once its been 10 second to allow the user to see the message display on the page.

Share Improve this question asked Jul 15, 2013 at 15:37 user2205196user2205196 1131 gold badge2 silver badges10 bronze badges 1
  • 1 Simple JavaScript works just fine: window.location.href = 'new url';. You can embed it in your page with Yii::app()->clientScript->registerScript(...). – Cᴏʀʏ Commented Jul 15, 2013 at 15:39
Add a ment  | 

2 Answers 2

Reset to default 5

You can call Yii::app()->clientScript->registerMetaTag() to register such a meta tag for the redirect:

Yii::app()->clientScript->registerMetaTag("10;url={$returnUri}", null, 'refresh');

This will generate:

<meta http-equiv="refresh" content="10;url=/foo/index.php?r=site/catalog"/>

which will produce a redirect after waiting 10 seconds.

It's not necessary to use yii if you're making a simple redirect. You can simply use Javascript and do this:

window.location.href = 'http://yournewURLgoeshere.tld/foo/bar';

Hope this helps!

Yii doesn't have a refresh method, but what is wrong with:

if (!headers_sent()) {
    header('Refresh:10;url='. $this->createUrl('controller/action'));
}
发布评论

评论列表(0)

  1. 暂无评论