dimanche 7 février 2016

typo3 ajax, mysterious if-else behavior

We have made an extension in typo3 (ver. 6.2). At a point we make a ajax call, where we want to save some values. In order to check if the user is logged in we use

$GLOBALS['TSFE']->fe_user->user['userid']

The userid for the two testusers are greater than 0. The (edited) php that is called looks like this:

<?php
$var = $GLOBALS['TSFE']->fe_user->user['userid'];
if($var > 0) {
    echo "var = ".$var."\n";
    echo "var > 0 - logged in!";
}else{
    echo "var = ".$var."\n";
    echo "var < 1 - not logged in.";
}
?>

Our problem is that when we look at the page-source, we can see the content from the if-condition:

var = 1 (or: var = 2)
var > 0 - logged in!

When we look at the console (F12), we can see the content from the else-condition:

var = 
var < 1 - not logged in.

The variable is empty here? The Apache error.log gives a notice:

 Trying to get property of non-object in .....

Can anyone explain what is going on? If it is a non-object, how come the variable is set to 1 (or 2)?

Aucun commentaire:

Enregistrer un commentaire