Sunday, January 9, 2022

[FIXED] yii redirect not working

Issue

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

Solution

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.



Answered By - TotPeRo

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.