Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yii redirect not working

In Yii framework $this->redirect function not working.

class TplUserNavigation extends CWidget{

public function run()
    {
        if(isset(Yii::app()->user->id) && Yii::app()->user->getState('userType') == 'User'){
         $users = Users::model()->findByAttributes(array('id'=>Yii::app()->user->id));
         $this->render('webroot.themes.'.Yii::app()->theme->name.'.views.layouts.tpl_navigation', array('users'=>$users));
        }else{
          $this->redirect('site/index'); 
    }
}
like image 753
aman Avatar asked Dec 07 '22 00:12

aman


2 Answers

Try:

$this->redirect("site/index"); 

or if you want to redirect to home page:

$this->redirect(Yii::app()->homeUrl);

From CWidget try:

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

Read more here about redirect from widget.

like image 174
TotPeRo Avatar answered Dec 14 '22 22:12

TotPeRo


Since you're just trying to go to the site's index, try something like this:

 $this->redirect(Yii::app()->baseUrl);

If you want to redirect the user to some other page than the home page try using:

 $this->redirect(Yii::app()->createUrl('controlller/action'));

This will come handy when you try url rewriting using yii url rules.

like image 43
Apoorv Joshi Avatar answered Dec 14 '22 20:12

Apoorv Joshi