Welcome Guest, Not a member yet? Register   Sign In
vbulleitn integration error
#1

[eluser]Evollution[/eluser]
to include vbulletin i just added to index.php :

Code:
<?php
$curdir = getcwd ();
chdir('forum');
require_once('./global.php');
chdir ($curdir);

echo $vbulletin->userinfo['username']; // Here I can display now my username with i logged in in the forum
?>

now if i try to use echo
Code:
$vbulletin->userinfo['username'];
in a view file i get an error :
Code:
Severity: Notice

Message: Undefined variable: vbulletin

Filename: views/template.php

Line Number: 15

i don't undersand why when i use $vbulletin->userinfo['username'] on index.php it works but if i use $vbulletin->userinfo['username'] on view files i get this error :\

I'm using CI 2.0
#2

[eluser]CroNiX[/eluser]
Because in index.php, $vbulletin is global, but in your own functions it isn't unless you are declaring it global within your classes/functions or passing it in.
Code:
class my_class extends CI_Controller
{
    public $vb;  //to hold the vbulletin object

    function __construct()
    {
        parent::__construct();
        global $vbulletin;      //globalize it
        $this->vb = $vbulletin; //stick it in a variable
    }

    function some_other()
    {
        if($this->vb->userinfo['username'] == 'somename')
        {
            //...
        }

        if(is_member_of($this->vb->userinfo, 6))
        {
            die('you are admin');
        }
    }
}

Heres a good thread on creating a library and autoloading it so you don't have to do this for each controller....
http://ellislab.com/forums/viewthread/110010/

It works for vb4 too.




Theme © iAndrew 2016 - Forum software by © MyBB