Try this to track the last valid URL used:
Add configuration to you:
'preload' => array( // preloading 'loginReturnUrlTracker' component to track the current return url that users should be redirected to after login 'loginReturnUrlTracker' ), 'components' => array( 'loginReturnUrlTracker' => array( 'class' => 'application.components.LoginReturnUrlTracker', ), ... ),
Put this file in the /LoginReturnUrlTracker.php components:
<?php class LoginReturnUrlTracker extends CApplicationComponent { public function init() { parent::init(); $action = Yii::app()->getUrlManager()->parseUrl(Yii::app()->getRequest()); // Certain actions should not be returned to after login if ($action == "site/error") { return true; } if ($action == "site/logout") { return true; } if ($action == "site/login") { return true; } // Keep track of the most recently visited valid url Yii::app()->user->returnUrl = Yii::app()->request->url; } }
Motin source share