Jump to content

isLoggedBack() code 505


guly

Recommended Posts

hello, i'm moving some code from 1.4 to 1.6.

this specific module does things only for logged users, as far as i know this check changed a lot since 1.4.

 

code examples that i've found around suggest to use isLoggedBack() call, present in employee context, and here i'm stuck.

 

reducing code as soon as i can, i'm trying this:

 

include_once("config/config.inc.php"); //yes, this exists 
if (Context::getContext()->employee->isLoggedBack()) {
        echo "is logged";
} else {
        echo "not logged";
}

and all i've got is an error 500.

i'm sure i miss something but i can't find what. could you please help me?

 

thanks

Link to comment
Share on other sites

you included core files of shop, that are necessary to run Context class?

i mean init php file and other important files

 

of course, the code is exactly what i pasted opening the topic.

 

what's wierd is that if i do:

if (Context::getContext()->customer->logged) {

 

it works.

 

i don't get why

if (Context::getContext()->customer->logged) { works

but

if (Context::getContext()->employee->isLoggedBack()) { doesn't

 

(i see the difference between customer and employee, but still i can't find the error here).

Link to comment
Share on other sites

  • 10 months later...

I know this is an old topic but maybe someone comes here through Google like I did. 
The problem is that there is no employee object in the context when noone is logged in, so calling the function isLoggedBack() on a non-object throws the error. 
What works is this : 
 

if(!Context::getContext()->employee || !Context::getContext()->employee->isLoggedBack()) { echo 'not logged in'; }
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...