I’ve discovered a strange problem that happens when a user not authenticated (so a Guest) try to access an action that requires the user to be authenticated, in this case the browser try to redirect to the site/login action but it goes in loop and it’s not able to open the login page.
I must specify that I change the standard structure of CRUD Yii, so I don’t have Class1Controller that extends directly CController but, as all my classes shares the same actions I’ve introduced an intermediate extension class in which I have all common actions, so i have
a class MyController that extends CController in which I have all common actions functions,
and then i have single Classes controllers that extends MyController so
Class1Controller that extends MyController
Class2Controller that extends MyController
etc…
I leaved in singles ClassXController only the informations specific of the class like name, defaultaction etc…
I’ve discovered that the loop problem is correlated to the fact I’ve moved the 2 functions
accessRules() and filters()
from ClassXController to MyController, if I leave one of the 2 functions (or both) in the ClassXController the problem disappear. I can’t find an explanation to this, by if I have these 2 functions in MyController (so in the intermediate class) there is the loop, I check also in debug and all seems to be the same, also the url to redirect.
Beneath I attach the 2 functions, that seems to have nothing special. I try with internet explorer and firefox, both goes in loop.
If someone could give me a tips about this, if you think I made something wrong, otherwise I hope this could be of help for other users in future (I lost 2 days to discover this)
thanks
/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow',
'actions'=>array('create','update', 'admin','delete', 'list', 'show'),
'users'=>array('@'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}