Set Returnurl Not Working

I have overridden some of the returnUrl related methods for CWebUser.


<?php


class WebUser extends CWebUser {

    

    

    public function init() {

        parent::init();

        //echo 'function called';exit;

    }

    

    /*

     * Override get return url

     */

    public function getReturnUrl($defaultUrl = null) {

        if ($defaultUrl === null) {

            $defaultReturnUrl = Yii::app()->getUrlManager()->showScriptName ? Yii::app()->getRequest()->getScriptUrl() : Yii::app()->getRequest()->getBaseUrl() . '/';

        } else {

            $defaultReturnUrl = CHtml::normalizeUrl($defaultUrl);

        }

        return $this->getState('__returnUrl', $defaultReturnUrl);

        echo Yii::app()->user->returnUrl;exit;

    }

    

    /*

     * Override set return url

     */

    public function setReturnUrl($value) {

        

        if ($value == "/site/page/?view=error404" 

                || $value == "/site/loginpage/" 

                || $value == "/site/loginpage/") {

            //echo $value;die; // Nothing to do

        } else {

            $this->setState('__returnUrl', $value);

        }

        echo Yii::app()->user->returnUrl;exit;

    }


}

I am sure that application is using this Class instead of CWebUser, As i have checked by overriding the init method.

Controller redirection code is


 if ($model->validate() && $model->login()) {

                $this->redirect(Yii::app()->user->returnUrl);

            }

When i login it doesn’t redirect user to anywhere.

I have put exit in both functions but it doesn’t exit in whole flow.

Can anyone please help me to understand, why these these two methods are not getting called automatically?

Hi

what is the purpose of overriding this returnurl ?..because it will work fine in framework itself :)

I just want framework not to set some url’s as returnUrl. As you can see three urls in setReturnUrl();

Hi,

Tell me case where you want to override this returnurl… I will tell you how to change returnurl without overriding…

I have a hidden form in my layout header for login -> action site/login.

Case 1:-

Form any action on site user can click on login button,user entered correct credentials and after login user should be redirected to same page.

Case 2:- User entered incorrect information it will redirect to site/loginpage and form will open in separate page instead of layout header. User enters correct credentials, Now user should be redirected to same page from where he/she clicked on layout login link.

Hi,

Following is the way to override returnurl. When you are using link…

This is important …‘params’=>array(‘returnUrl’=>‘your action’)

array(‘label’=>‘delete’, ‘url’=>’#’, ‘linkOptions’=>array(‘submit’=>array(‘delete’,‘id’=>$model->invoiceid),‘confirm’=>Yii::t(‘deutsch’,‘delete’),‘params’=>array(‘returnUrl’=>‘admin’))),