传递给phpbb_generate_debug_output()的参数x必须是phpbb \ user的一个实例

时间:2016-07-19 21:40:15

标签: php symfony phpbb

我正在使用phpBB创建一个简单的社区。所以,我想创建一个costum网站,我想在其中显示某些组的成员。

代码是我第一次尝试创建costum网站。

我有members.php

<?php
    define('IN_PHPBB', true);
    $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);

    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();

    // Inits Languagefile
    page_header('test');

    // Groups that should displayed
    $group_ids = array(
        5,
        9,
    );

    // Get Groups from Database
    $sql = 'SELECT group_id, group_name, group_desc FROM ' . GROUPS_TABLE . ' WHERE ' . $db->sql_in_set('group_id', $group_ids);
    $result = $db->sql_query($sql);

    // Write Data for each Group
    while ($row = $db->sql_fetchrow($result)) {
        $template->assign_block_vars('unit', array(
            'GROUPNAME'     => $row['group_name'],
            'DESCRIPTION'   => $row['group_desc'],
        ));

        // Get Groupmembers from Database
        $sqlusers = 'SELECT user_id FROM ' . USER_GROUP_TABLE . ' WHERE group_id = ' . $row['group_id'];
        $users = $db->sql_query($sqlusers);

        // Get User from Database
        while ($user = $db->sql_fetchrow($users)) {

            $sql_arr = array(
                'SELECT'    => 'u.user_id, u.username, u.user_avatar, r.rank_title, r.rank_image',
                'FROM'      => array(
                    USERS_TABLE => 'u',
                    RANKS_TABLE => 'r'
                ),
                'WHERE'     => 'u.user_id = ' . $user['user_id'] . ' AND u.user_rank = r.rank_id',
            );
            $sqluserdata = $db->sql_build_query('SELECT', $sql_arr);

            $userdata = $db->sql_query($sqluserdata);         

            // Write Data for each User
            while($single = $db->sql_fetchrow($userdata)) {
                $template->assign_block_vars('unit.member', array(
                    'USERID'    => $single['user_id'],
                    'USERNAME'  => $single['username'],
                    'AVATAR'    => $single['user_avatar'],
                    'RANK'      => $single['rank_title'],
                    'RANGIMAGE' => $single['rank_image'],
                ));
            }
            $db->sql_freeresult($userdata);
        } 
        $db->sql_freeresult($users);
    }
    $db->sql_freeresult($result);

    // Load Template
    $template->set_filenames(array(
        'body' => 'members.html',
    ));

    // End Controller
    make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
    page_footer();
?>

导致样式/ * / members.html:

<!-- INCLUDE overall_header.html -->

<div id="sub-header">
    <div class="chunk">
        <div class="sub-header-title">
            <h2 class="titlespace">Mitglieder</h2>
        </div>
    </div>
</div>

<div class="background-main">
    <div class="chunk">    
        <!-- BEGIN unit -->
        <div class="unit">
            <h3>{unit.GROUPNAME}</h3>
            <p>{unit.DESCR}</p>

            <!-- BEGIN unit.member -->
            <div class="unitmember" style="background-color:red;">
                <p>{unit.member.USERNAME}</p>
                <p>{unit.member.AVATAR}</p>
                <p>{unit.member.USERID}</p>
                <p>{unit.member.RANK}</p>
                <p>{unit.member.RANKIMAGE}</p>
            </div>
            <!-- END unit.member -->

        </div>
        <!-- END unit -->
    </div>
</div>


<!-- INCLUDE jumpbox.html -->
<!-- INCLUDE overall_footer.html -->

我通过var_dump测试了数据输出,每次都很好......但是每当我解析模板时,它都会抛出这个错误:

“可捕获的致命错误:传递给phpbb_generate_debug_output()的参数4必须是phpbb \ user的实例,给定布尔值,在5431行的C:\ xampp \ htdocs \ jgzga \ includes \ functions.php中调用,并在C中定义:\ xampp \ htdocs \ jgzga \ includes \ functions.php on line 5343“

我从未接触过phpbb的核心文件...所以...也许你们中的一些人可以帮助我。 ;)

1 个答案:

答案 0 :(得分:0)

  1. 至于3.1版本的phpBB论坛已发布,您不应在 ext / 目录之外放置任何自定义代码。所有修改都应该写成带有控制器,服务,DI等的扩展。更多信息:https://www.phpbb.com/extensions/writing/
  2. 在您的情况下,由 $ user 变量引起的此错误在phpBB中是全局的并且具有特殊含义 - 它表示当前用户的对象。你在循环中覆盖它。在最后一次迭代时,它变为布尔值false,然后传递给phpbb_generate_debug_output()函数。重命名此变量或(更好)将代码重写为扩展名。