Redirect From Widget ?

I was reading this forum post which says why redirecting from the widget is a bad MVC practice but may be good from the DRY point of view.

Forget for the moment, good or bad - the question is how do i actually redirect from a widget ?

This code:




$this->redirect(array('view','site/confirmsubscription'));



yields the error:

thanks for the help ::)

Dear Friend

It should be




$this->owner->redirect(array('view','site/confirmsubscription'));



What does "site/confirmsubscription" mean?

Regards.

thanks again :rolleyes:

However,




$this->owner->redirect(array('view','site/confirmsubscription'));

is not working…

site/confirmsubscription is the controller/action respectively.

the problem is, this widget is located on several controller induced pages.

So the widget may be accessed from any controller.

Dear Friend

Then the redirect method should be declared in the following way.




$this->owner->redirect(array('site/confirmsubscription'));



or additional Parameters should be appended like below.




$this->owner->redirect(array('site/confirmsubscription','id'=>$this->id));//or $model->id like so.



thanks for replying.

unfortunately that doesnt work ???

If i access the widget from a say another page say from user/login,

it redirects to /user/site/confirmsubscription instead of /site/confirmsubscription

resulting in a 404 error :unsure:

Dear Friend

I created a widget and put it inside the components folder.




<?php

class RedirectWidget extends CWidget

{

         public function run()

         {

                $this->owner->redirect(array("site/login"));

         }

}   

?>



At any controller if I call the widget like below, it redirects to login page.




$this->widget('RedirectWidget');



One more suggestion is to put a forward slash at the beginning.




$this->owner->redirect(array('/site/confirmsubscription'));



ha that backslash did the trick :)

it is late night or rather wee hours in India…

like me, you too seem to be nocturnal :D

thanks once again