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

Fetch Forum ID by Thread ID in Non-Object

Discussion in 'XenForo Development Discussions' started by mjda, Jun 2, 2013.

  1. mjda

    mjda Active Member

    As the title says, I'm trying to fetch the forum id (node_id) by the 'thread_id'. I tried to use the $this->getModelFromCache['XenForo_Model_Forum'] method, so I could use getForumByThreadId, but I guess I can't do that where I'm trying to do it. I get the following error: Fatal error: Using $this when not in object context in /dirs/to/myAddon/Listener.php on line 165.

    Is there a way to do this, somehow, without having to make another call to the dB?
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    You're trying to use $this in your Listener which won't work because it's not in an object context.

    Also, the getModelFromCache function won't be available in your Listener so trying to call it as if it is won't work.

    The correct way to do this in a Listener is:

    PHP:
    XenForo_Model::create('XenForo_Model_Forum')->getForumByThreadId($threadId);
     
    mjda likes this.
  3. mjda

    mjda Active Member

    Thanks Chris Deeming. That did add an additional query to each thread view, but it works.
     
  4. xf_phantom

    xf_phantom Well-Known Member

    Inside the thread view you have access to

    $thread
    $forum


    what event is yous listener using? template hook?
     
  5. mjda

    mjda Active Member

    Yes.
     

Share This Page