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 withYii::app()->clientScript->registerScript(...)
. – Cᴏʀʏ Commented Jul 15, 2013 at 15:39
2 Answers
Reset to default 5You 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'));
}