CodeIgniter and PhPBB 3.1.3 integration

2019-04-12 16:42发布

问题:

I develop a website site based on CodeIgniter, the latest version 2.2.1 and I installed a PhPBB forum (version 3.1.3).

I would like to use the functions of the forum on my web site (like the connection/profile etc.). I've looked on this site : http://www.3cc.org/blog/2010/03/integrating-your-existing-site-into-phpbb3/ to simply display my pseudo.

My Controller is just a copy/paste of the first paragraph

class Forum_test extends CI_Controller{

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
         define('IN_PHPBB', true);
         $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : 'forum/';
         $phpEx = substr(strrchr(__FILE__, '.'), 1);
         include($phpbb_root_path . 'common.' . $phpEx);
         // Start session management
         $user->session_begin();
         $auth->acl($user->data);
         $user->setup();
    }
}

And my problem is when I try to use this code, I have the following error

Fatal error: Call to a member function header() on a non-object in /var/www/forum/phpbb/session.php on line 224

But if I create a simple document with only

<?php
define('IN_PHPBB', true);

$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : 'forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management

$user->session_begin();
$auth->acl($user->data);
$user->setup();
?>

It works (I don't have any error)

Do you have any idea of what is wrong with my code ?

Thank you.

回答1:

So ... I found the solution after long research ...

https://www.phpbb.com/community/viewtopic.php?f=71&t=2287546

The solution was to add global variables to the function index

global $request;
global $phpbb_container;
global $phpbb_root_path, $phpEx, $user, $auth, $cache, $db, $config, $template, $table_prefix;
global $request;
global $phpbb_dispatcher;
global $symfony_request;
global $phpbb_filesystem;


回答2:

I have also needed to integrate phpbb into codeigniter base website and face many problems and finally able to do it. If you need it you can find all code at phpbb integration in codeigniter it also contains phpbb version which I have used to integrate as well as doubtful. If you want to improvement in the code. Please frok me on github.