Problem with isLoggedIn() and version preview
Permalink
I have a quick check built into my template to see if someone is logged in or not by using isLoggedIn() - this seems to cause a problem when using the versions feature and comparing different versions however. In the preview I receive an error . Is there any way to just prevent the isLoggedIn() section of the template from running in the preview?
call to a member function isLoggedIn() on a non-object...
Try calling $u = new User(); right before calling isLoggedIn()
Thanks. Just to confirm - do I still need the global $u if I'm using $u = newUser();? In other words should it look something like this or Thanks, I appreciate the help.
global $u; $u = new User(); if ($u -> isLoggedIn()) {
$u = new User(); if ($u -> isLoggedIn()) {
Always use:
That will just grab the current logged in user from the session. It won't even make a database query so there's really very little overhead.
the global $u isn't always a valid user object.
$u = new User();
That will just grab the current logged in user from the session. It won't even make a database query so there's really very little overhead.
the global $u isn't always a valid user object.
Perfect, thank you.