Log in

View Full Version : Function add on a non-object issue


Abronsyth
03-19-2017, 12:27 PM
Hey all, hoping someone more PHP savvy than myself can help out here.

I'm working on adding a new module to my theme and am basing it off of the other modules. Well, I am encountering an issue now in my class file.
Fatal error: Call to a member function add() on a non-object in /home/teratria/public_html/classes/class_userbar.php on line 56

This is the script that it is struggling with;

protected function setUsercp(){
$mysidia = Registry::get("mysidia");
$profile = $mysidia->user->getprofile();
date_default_timezone_set("America/New_York");
$time = date('h:i a');
//$this->UserCP->add(new Comment("<img src='http://teratria.x10host.com/images/theme/clock.png'/> {$time}"));
$profileLink = new Link("http://teratria.x10host.com/profile/view/{$mysidia->user->username}");
$profileLink->setText("<img src='http://teratria.x10host.com/images/theme/user.png'/> {$mysidia->user->username}");
$this->usercp->add($profileLink);

$this->setDivision($this->usercp);
}


Is anyone able to see what I am doing wrong?

Silver_Brick
03-19-2017, 03:26 PM
are you making a userbar ?? i could help you to make it

Abronsyth
03-19-2017, 03:51 PM
Sort of, yes, I am making a user control panel that is a separate widget from the sidebar.

If I could just get the function working properly then everything else would be fine, so I already have everything coded, just need to find out what's causing my function to bug out.

Hall of Famer
03-19-2017, 05:57 PM
Well seems to me that this is where you get the error:

$this->usercp->add($profileLink);

If so, you have uninitialized property $usercp for your class, or this property does not exist(a typo, or it never exists in the first place). You need to provide more information here, maybe posting the entire class file will do.

Abronsyth
03-19-2017, 10:21 PM
I couldn't wrap my head around it, but I found an alternative solution following Kyttias's code bits here;
http://mysidiaadoptables.com/forum/showthread.php?t=4599

Thanks y'all for the replies!

Silver_Brick
03-19-2017, 11:13 PM
it can be done in template.tpl of template file ^^ but first assign the variables ^^