Yii Framework Forum: Redirect From Widget ? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Redirect From Widget ? Rate Topic: -----

#1 User is offline   sanguina 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 22-July 12

Posted 23 February 2013 - 04:13 PM

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:

Quote

SubscriberFormWidget and its behaviors do not have a method or closure named "redirect".


thanks for the help ::)
until I become certain that there is no certainty.
0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 23 February 2013 - 04:21 PM

Dear Friend

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

What does "site/confirmsubscription" mean?

Regards.
0

#3 User is offline   sanguina 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 22-July 12

Posted 23 February 2013 - 04:32 PM

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.
until I become certain that there is no certainty.
0

#4 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 23 February 2013 - 04:41 PM

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.

0

#5 User is offline   sanguina 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 22-July 12

Posted 23 February 2013 - 04:54 PM

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:
until I become certain that there is no certainty.
0

#6 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 23 February 2013 - 05:15 PM

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'));

0

#7 User is offline   sanguina 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 22-July 12

Posted 23 February 2013 - 05:39 PM

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
until I become certain that there is no certainty.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users