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:


yields the error:

thanks for the help ::)

Dear Friend

It should be


What does "site/confirmsubscription" mean?


thanks again :rolleyes:



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.


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.


class RedirectWidget extends CWidget


         public function run()






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


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


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