Set returnUrl by overriding loginRequired()

By default Yii doesn’t store host information in returnUrl function (it stores only “/some/path” without “http://company.website.com”). 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. http://company.website.com/some/path).

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() {

        $app=Yii::app();

        $request=$app->getRequest();


        if(!$request->getIsAjaxRequest())

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


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

            if(is_array($url)) {

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

                $url=$app->createUrl($route,array_splice($url,1));

            }

            $request->redirect($url);

        }

        else

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

    }


}



Now, Yii::app()->user->returnUrl gives me what I need (http://company.website.com/some/path). The question is - is it right way to do things like that?

Looks good to me. :)

Thanks. So far everything works as expected =)