Jquery Mobile & Yii

Hello Guys,

I’m working for a project using JQueryMobile & Yii without using Yii’s Ajax functions, now having problem with authentication. And I’m not sure Yii query works all fine with JQueryMobile or not.

My Issue:

When I access a authentication required page, it can’t redirect to login page automatically. If I disable JQueryMobile’s ajax functions, it works just fine.[something like ajaxEnabled = false]

After some searching, I found I need to set ‘loginRequiredAjaxResponse’ in order to enable the redirection,


CWebUser.php

public function loginRequired()


{


	$app=Yii::app();


	$request=$app->getRequest();





	if(!$request->getIsAjaxRequest())


	{


		$this->setReturnUrl($request->getUrl());


		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);


		}


	}


	elseif(isset($this->loginRequiredAjaxResponse))


	{


		echo $this->loginRequiredAjaxResponse;


		Yii::app()->end();


	}





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


}

It seems Yii just end current Session, so it will redirect to Login page, unfortunately, it not works for me.

my config/main.php


'components'=>array(


	'user'=>array(


		// enable cookie-based authentication


		'allowAutoLogin'=>true,


		'loginUrl'=>'site/login',


		'loginRequiredAjaxResponse' => 'YII_LOGIN_REQUIRED',


		'class' => 'CWebUser',


	),

Although I can work around this issue by enforcing to redirect to login page, like commenting out $request->getIsAjaxRequest() checking, but I can’t understand it why Yii’s function not work for me. It’s better to leverage Yii’s function I believe, but somehow it just can’t redirect automatically. Need your help, thanks.