سؤال

I have phpbb3 integrated in my site.

I have the login in my header webpage like is explained in https://wiki.phpbb.com/External_Login.

All works fine, but I would like to go a bit further, I would like to have the navbar in my website header, then I could see new messages and user profile in my website header. I am using this code:

    <?php
define('IN_PHPBB', true);
$phpbb_root_path = '../phpbb3/';
$phpEx           = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

?>  


<div class="registro">

<?php
if ($this->_rootref['S_USER_LOGGED_IN']) {
?>

<div class="navbar" style="background-image:url('../img/opaco.png');">
     <div class="inner"><span class="corners-top"><span></span></span>



     <?php
    if (!$this->_rootref['S_IS_BOT'] && $this->_rootref['S_USER_LOGGED_IN']) {
?>

     <ul class="linklist leftside">
        <li class="icon-ucp">
           <a href="<?php
        echo (isset($this->_rootref['U_PROFILE'])) ? $this->_rootref['U_PROFILE'] : '';
?>" title="<?php
        echo ((isset($this->_rootref['L_PROFILE'])) ? $this->_rootref['L_PROFILE'] : ((isset($user->lang['PROFILE'])) ? $user->lang['PROFILE'] : '{ PROFILE }'));
?>" accesskey="e"><?php
        echo ((isset($this->_rootref['L_PROFILE'])) ? $this->_rootref['L_PROFILE'] : ((isset($user->lang['PROFILE'])) ? $user->lang['PROFILE'] : '{ PROFILE }'));
?></a>
              <?php
        if ($this->_rootref['S_DISPLAY_PM']) {
?> (<a href="<?php
            echo (isset($this->_rootref['U_PRIVATEMSGS'])) ? $this->_rootref['U_PRIVATEMSGS'] : '';
?>">
<?php
            echo (isset($this->_rootref['PRIVATE_MESSAGE_INFO'])) ? $this->_rootref['PRIVATE_MESSAGE_INFO'] : '';
?></a>)<?php
        }
        if ($this->_rootref['S_DISPLAY_SEARCH']) {
?> &bull;

           <?php
        }
?>

        </li>
     </ul>
     <?php
    }
?>


     <ul class="linklist rightside">

        <?php
    if (!$this->_rootref['S_IS_BOT']) {
        if ($this->_rootref['S_DISPLAY_MEMBERLIST']) {
?><?php
        }
        if (!$this->_rootref['S_USER_LOGGED_IN'] && $this->_rootref['S_REGISTER_ENABLED'] && !($this->_rootref['S_SHOW_COPPA'] || $this->_rootref['S_REGISTRATION'])) {
?><li class="icon-
register"><a href="<?php
            echo (isset($this->_rootref['U_REGISTER'])) ? $this->_rootref['U_REGISTER'] : '';
?>"><?php
            echo ((isset($this->_rootref['L_REGISTER'])) ? $this->_rootref['L_REGISTER'] : ((isset($user->lang['REGISTER'])) ? $user->lang['REGISTER'] : '{ REGISTER }'));
?></a></li><?php
        }
?>

           <li class="icon-logout"><a href="<?php
        echo (isset($this->_rootref['U_LOGIN_LOGOUT'])) ? $this->_rootref['U_LOGIN_LOGOUT'] : '';
?>" title="<?php
        echo ((isset($this->_rootref['L_LOGIN_LOGOUT'])) ? $this->_rootref['L_LOGIN_LOGOUT'] : ((isset($user->lang['LOGIN_LOGOUT'])) ? $user->lang['LOGIN_LOGOUT'] : '{ LOGIN_LOGOUT }'));
?>" accesskey="x">
<?php
        echo ((isset($this->_rootref['L_LOGIN_LOGOUT'])) ? $this->_rootref['L_LOGIN_LOGOUT'] : ((isset($user->lang['LOGIN_LOGOUT'])) ? $user->lang['LOGIN_LOGOUT'] : '{ LOGIN_LOGOUT 
}'));
?></a></li>
        <?php
    }
?>

     </ul>

     <span class="corners-bottom"><span></span></span></div>
  </div>


<?php
} else
//user is not logged in  
    {
    include('loginGeneral.php');
    // this is a login form
}
?>      


</div>   

I use a custom login form if the user is not register, but if the user is register I show the navbar with some modified.

That code works when I am in the phpbb3 menu in my site, I mean when I am surfing within the forum I can show the navbar in my website header, but when I am for example in my home page I get

Fatal error: Using $this when not in object context in C:\wamp\www\esp\cabecera.php on line 2

I think the file maybe load some files and change $this->_rootref in the whole code, but I am a bit lost.

Edited: I am still stuck with this, anyone can help me please? I think that I have to replace $this->_rootref with $_rootref and probably add some include but I don't know which. Thanks

هل كانت مفيدة؟

المحلول

Un poco tarde quizas, pero $this-> se refiere al objeto que esta declarado, por eso no te funciona fuera del contexto, en tu site donde no existe ese objeto (Object Oriented Programming).

Lo mas seguro es que se refiera al objeto forum, donde esta declarada la variable _rootref

Lo mas facil seria ver qué objecto es $this en ese contexto y llamarlo directamente con PHP desde fuera, sin usar Object Oriented o averiguar quien declara la variable _rootref['S_USER_LOGGED_IN'] y usar eso directamente.

Puedes probar poniendo un echo $this-> _rootref en esa página para ver a que se traduce y tratar de usarlo luego, si te dice que no existe, tendras que ver donde esta declarado _rootref['S_USER_LOGGED_IN'] y trabajar con eso.

(English)

A bit late maybe, but $this-> is refering to a declared object in that page using Object Oriented Programming. That object only exists on that context, it does not exist outsidte of it like in your other non-phpbb pages so you'll always get that error, no matter what.

I haven't looked too closely at the code but it's probably referring to the forum object or whichever object holds the _rootref variable.

The easiest thing to do would probably be to find out what object $this refers to in that context and try to call that from your outside pages. Or find out where _rootref['S_USER_LOGGED_IN'] is declared and use that function in your pages or a variation of it.

You can try echoing it out on that page: echo $this->_rootref to see if that exists or echo $this->_rootref['S_USER_LOGGED_IN'] if it doesn't. Other than that, look for _rootref['S_USER_LOGGED_IN'] in the project to see where it's being declared.

Hope this helps someone.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top