Invalid return URL in Yii structure

I used Yii::app()->user->returnUrl, but it always redirects me to localhost/index.php. Is there any specific configuration or some code fragments that I have to write to other programs? If you have other solutions, let me know about it.

+3
source share
3 answers

@aslingga, could you explain what you are trying to do with returnUrl? Are you just trying to get back to where you are after logging in, or are you using it somewhere else?

This is from the Yii documentation :

. , URL ( AJAX url) , . , loginUrl, URL . , .

, , URI , , . , , .

, , - print_r($_SESSION);, , returnUrl . , index.php returnUrl - .

CWebUser, getState setState .

+3

, , , , -, .

getReturnUrl

URL- Yii . , , , URL , :

Yii::app()->user->getReturnUrl('site/internal');

, , , ​​ , ,

Yii::app()->user->setReturnUrl('site/visitedpage');

, , , .

, URL . URL- , . ,

Yii::app()->user->getReturnUrl(Yii::app()->params['defaultReturnUrl']);

, , .

, getReturnUrl - , "/index.php", "/". , . .

CWebUser

class WebUser extends CWebUser {
    // default return URL property
    public defaultReturnUrl;

    // override the getReturnUrl method
    public function getReturnUrl($defaultUrl=NULL) {
        if ($defaultUrl === NULL) {
            $defaultReturnUrl = $this->defaultReturnUrl;
        }
        else {
            $defaultReturnUrl = CHtml::normalizeUrl($defaultUrl);
        }
        return $this->getState('__returnUrl',$defaultReturnUrl);
    }
}

.

'user' => array(
    'class' => 'WebUser',
    'defaultReturnUrl' => 'site/internal'
)

URL- , URL- setReturnUrl.

+3

I think you should install it:

Yii::app()->user->setReturnUrl('controller/action');
0
source

Source: https://habr.com/ru/post/1771633/


All Articles