PDA

View Full Version : Custom Class - vBulletin


JamesTalbot
01-18-2009, 01:44 AM
Hello,

Looking to create a custom class called League. This is going to be integrated with vBulletin. I want to use be able to use the $vbulletin->userinfo[]; inside the methods...if that makes sense. Here is what i have.

League.php

class League
{
private $vbulletin;

public function __constructor($vbulletin)
{
global $vbulletin;
}

public function showNews()
{

echo $this->userinfo['username'];

}
}

config.php

$cur_dir = getcwd();
chdir('./forums/');
require_once('./global.php');
chdir($cur_dir);
include ('League.php');
$league = new League($vbulletin);

index.php

include ('config.php');
$league->showNews();


I was hoping that it would display the username but obviously i am doing something very wrong.

How do i create a custom class and be able to use the $vbulletin, $db methods/objects etc?

Sorry for confusing questions. Hope someone can help me with this. :) Thanks.

Dismounted
01-18-2009, 03:10 AM
Firstly, a constructor method is "__construct()". Secondly, "$this" refers to the current object, not another object. Thirdly, you actually need to populate your variables. :)
class League
{
private $vbulletin;

public function __construct($vbulletin)
{
$this->vbulletin = $vbulletin;
}

public function showNews()
{
echo $this->vbulletin->userinfo['username'];
}
}

JamesTalbot
01-18-2009, 08:54 AM
Thank you so much!!!

:)

Dismounted
01-18-2009, 09:50 AM
By the way, keep in mind that magic methods (e.g. __construct()) and private/protected/public/static/etc. keywords only exist in PHP 5.

Andreas
01-18-2009, 11:22 AM
Don't copy the object, reference it.


class League
{
private $vbulletin;

public function __construct(&$vbulletin)
{
$this->vbulletin = $vbulletin;
}
}