• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Problem with ControllerPublic

#1
Hi, I'm testing for customization XenForo, to see if you can lend a hand with the following code:

PHP:
class Puntos_ControllerPublic_Thread extends XFCP_Puntos_ControllerPublic_Thread
{
    public function actionAddReply()
    {
        // get parent       
        $parent = parent::actionAddReply();   
        
        // get userId
        $userId = XenForo_Visitor::getUserId();
        $points = '10';
        
        // conex db
        $db = $this->_getDb();
        
        // sumar puntos
        $db->query('UPDATE xf_user SET trophy_points = trophy_points+? WHERE user_id = ?', array($points, $userId));
        
        return $parent;
    }
}

I get error and does not update the field trophy_points.

A greeting.
 

Syndol 2.0

Active member
#3
It has been a while but at least in the older versions of XF I do believe the function _getDb() was not available in the ContrllerPublic class.
Try $db = XenForo_Application::getDb();
 

Robust

Well-known member
#5
I missed that part. It still doesn't have a _getDb() function I think. All direct database touching should be done in a model, so you should be using a model for adding trophy points like that. Also probably a bad idea to add trophy points manually, since if you rebuild them you will lose the points.
 
#6
It has been a while but at least in the older versions of XF I do believe the function _getDb() was not available in the ContrllerPublic class.
Try $db = XenForo_Application::getDb();
Thank you very much, now it works. ;)

P.S. Some wiki with all the information XenForo for programming?
 

Robust

Well-known member
#7
P.S. Some wiki with all the information XenForo for programming?
Unfortunately not, but it should be very easy to get to grips with everything by searching in this forum, reading some of the user made tutorials there are and just navigating through the code. And of course you can ask questions all you want.
 
#8
Unfortunately not, but it should be very easy to get to grips with everything by searching in this forum, reading some of the user made tutorials there are and just navigating through the code. And of course you can ask questions all you want.
Thank you, the truth is I was using vb, and returning to XenForo, there are plugins that are difficult to perform, but in about an hour and have my point system topic, answers, etc... ;)

Try not crazy with questions you again :)

P.S. Sorry for my English.