Just moved my app to a production server and having a problem. I require the user to login to access any page other than the login page with the following code. It works fine on my localhost (XAMPP), but the production server gives me the error: Trying to get property of non-object (focused on the Yii::app()->controller->id). Am I missing a module or have another problem?
All my user-level controllers inherit from a custom base controller. In that controller I have code that checks if user isGuest and redirects to login page.
example:
public function beforeAction()
{
if(Yii::App()->user->isGuest) {
$this->redirect(Yii::app()->user->loginUrl);
return false;
} elseif (!$this->isOwnerOrAdmin()) {
throw new CHttpException(403, 'Action is forbidden. Hit the road, Jack.');
}
return true;
}
My isOwnerOrAdmin function just checks if the user has role of admin or ‘owns’ the content.