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

Problem with ControllerPublic

Discussion in 'XenForo Development Discussions' started by OsKaR, Oct 16, 2016.

  1. OsKaR

    OsKaR Member

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

    class Puntos_ControllerPublic_Thread extends XFCP_Puntos_ControllerPublic_Thread
        public function 
    // 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));

    I get error and does not update the field trophy_points.

    A greeting.
  2. Robust

    Robust Well-Known Member

    What's the error?
    OsKaR likes this.
  3. Syndol 2.0

    Syndol 2.0 Member

    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();
    OsKaR likes this.
  4. Chris D

    Chris D XenForo Developer Staff Member

    You're correct. I will hazard a guess that the error will be Call to undefined method ...::_getDb() etc.
    OsKaR and Syndol 2.0 like this.
  5. Robust

    Robust Well-Known Member

    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.
    OsKaR likes this.
  6. OsKaR

    OsKaR Member

    Thank you very much, now it works. ;)

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

    Robust Well-Known Member

    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.
    OsKaR likes this.
  8. OsKaR

    OsKaR Member

    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.

Share This Page