Set returnUrl by overriding loginRequired()

By default Yii doesn’t store host information in returnUrl function (it stores only “/some/path” without “”). This is a problem for me, because my application dynamically creates subdomains for users (companies) and I need to store host information in returnUrl as well (i.e.

I’ve copied and changed a bit loginRequired() function to store whole path and pasted it in my CWebUser component like this:

class WebUser extends CWebUser {

    // some code here

    public function loginRequired() {




            $this->setReturnUrl($request->hostInfo.'/'.$request->pathInfo); <----- here

        if(($url=$this->loginUrl)!==null) {

            if(is_array($url)) {

                $route=isset($url[0]) ? $url[0] : $app->defaultController;






            throw new CHttpException(403,Yii::t('yii','Login Required'));



Now, Yii::app()->user->returnUrl gives me what I need ( The question is - is it right way to do things like that?

Looks good to me. :)

Thanks. So far everything works as expected =)