Delayed Redirect

Hi

I was wondering if there is a way to delay a CController::redirect() call? For example by 10 seconds?

Or would I need to place the html in the view itself and the page I wish the user to be redirected to?



<META HTTP-EQUIV="refresh" CONTENT="10;URL=the-other-page.html">


Chris

You can call Yii::app()->clientScript->registerMetaTag() to register such a meta tag from anywhere in your code.

Thank you :)

I am running that from my controller action and then rendering the view, however, this doesn't seem to be working:



<?php


Yii::app() -> clientScript -> registerMetaTag('10', null, 'refresh', array('url' => 'index/'));


$this -> controller -> render('confirm');


The registered meta tag is not being added above the <title> attribute.

Chris

This should work…

It's not being rendered in the view shrugs

Could you insert print_r($this->_metas) at line 102 in CClientScript.php and see what is displayed?

I placed that at line 102 in C:\wamp\www\yii\framework\web\CClientScript.php

Nothing was displayed when i refreshed the action that registers the meta tag.

Chris

What if you add a die() statement after this print_r()? I suspect you are redirecting to another page already.

Placing a die after the print_r gives me a page with an empty array.

Scrap that, I was loading the wrong controller action. Loading the correct action, It doesn’t die at all  ???.

I'm confused lol

That's weird. Insert a print_r($this->_metas) at line 368 of CClientScript.php?

Ok, will do in a second, I just added



Yii::app() -> clientScript -> registerScript("test", "test.js");


this then causes a die with the following array:



Array


(


    [a:3:{s:3:"url";s:6:"index/";s:7:"content";s:1:"1";s:10:"http-equiv";s:7:"refresh";}] => Array


        (


            [url] => index/


            [content] => 1


            [http-equiv] => refresh


        )





)


From this i guess that the meta tag would now be rendered into the head, but it looks as if the JavaScript file i just tried to add wouldn't be?

Chris

Adding print_r($this->_metas)  to line 368 and remove Yii::app() -> clientScript -> registerScript("test", "test.js"); from the action just gives me an empty array and the page fails to die.

Chris

Thanks. I found the bug. It's fixed in SVN.

:-[ Still having issues with it, here is my entire code:

Controller



<?php


/**


* Register Controller


*/


class RegisterController extends CController {


	


	/**


	* Actions overide function


	* @return array actions


	*/


	public function actions() {


		return array(


			'index' => 'application.controllers.actions.register.IndexAction',


			'confirm' => 'application.controllers.actions.register.ConfirmAction',


		);


	}


}


Confirm Action



<?php


/**


* Register controller confirm action 


*/


class ConfirmAction extends CAction {


	/** 


	* Run action


	*/


	public function run() {


		Yii::app() -> clientScript -> registerMetaTag('10', null, 'refresh', array('url' => 'index/'));


		// Yii::app() -> clientScript -> registerScript("test", "test.js"); // Works with this un comented


		$this -> controller -> render('confirm');


	}


}


Confirm View



<h2>Thank you for registering your new account.</h2>


<p>An email confirm your account creation will be sent to you.</p>


<p>You will need to activate your account by clicking the activation link contained within the email.</p>


<p>If your account is not activated within 30 days it will be removed from our system.</p>


<p>Thank you for registering.</p>


I have downloaded the updated from the SVN.

shrugs

Did you get the latest code from 1.0 branch SVN? The change is to add the following line to registerMetaTag() method:

	$this-&gt;_hasScripts=true;

nope i updated my svn from http://yii.googlecode.com/svn/trunk.

Doesn’t matter, Ive added that line to the registerMetaTag()  method, all seems to be working now :)

Thank you very much. :)

Chris

hi guys :)

I use this code and all works perfectly:


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

generated html:


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

in contrast to:


Yii::app()->clientScript->registerMetaTag("100", null, 'refresh', array('url' => $returnUri));

html:


<meta http-equiv="refresh" content="100" url="/test/index.php?r=site/catalog"/>

PS: 1.0.8