Frank Vèssia Posted November 16, 2011 Share Posted November 16, 2011 I cannot understand why i can't get role of user. $userid = 40; $role = $roles->get("premium"); $uid = (int) $userid; $u = $users->get($uid); if ($u->hasRole($role)){ ...stuff } i get a fatal error: Method NullPage::hasRole does not exist or is not callable in this context Link to comment Share on other sites More sharing options...
Soma Posted November 16, 2011 Share Posted November 16, 2011 Shouldn't it be hasRole("string"); ? You load the role as object and not as string, and hasRole expects the name (string). Link to comment Share on other sites More sharing options...
Frank Vèssia Posted November 16, 2011 Author Share Posted November 16, 2011 already tried using string.... I guess the problem is the user. If i use this function with current user ($user) it works... Link to comment Share on other sites More sharing options...
Soma Posted November 16, 2011 Share Posted November 16, 2011 NullPage::hasRole says to me there's no "userpage" found so its returning NullPage, and there's no method on NullPage. Link to comment Share on other sites More sharing options...
ryan Posted November 16, 2011 Share Posted November 16, 2011 This line failed to load a user: $u = $users->get($uid); User ID 40 doesn't exist in the system because anytime PW returns a NullPage that means it didn't find what you were looking for. The best way to check if you got a NullPage is to see if the returned has an ID. So your last section of code should be something like this: if ($u->id && $u->hasRole($role)){ ...stuff } Btw, ID 40 is the default ID for the 'guest' user account, so it would be unusual if that really is the ID of the user and it didn't load. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now