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

Easiest way to fetch thread_id from post_id?

Discussion in 'XenForo Development Discussions' started by Marcus, Nov 28, 2012.

  1. Marcus

    Marcus Well-Known Member

    In node_forum_level_2 I want to replace the lastpost links from posts/1234 with threads/32/unread. This template is created from getExtraDataForNodes(array $nodeIds) [NodeHandler] which fetches its data from getExtraForumDataForNodes [Model], but this function only fetches the post_id.

    From what I know, I can not use post_id to get a /thread/ route link with <xen:link > in the templates.
  2. Chris D

    Chris D XenForo Developer Staff Member

    There's a function in the post model that fetches the parent data.

    I would expect you would have to pass that to the forum controller. But, of course the thread title is available to the template so I would expect the thread id to be available too.

    Have you tried putting {xen:helper dump, $posts} or {xen:helper dump, $threads} in the template? I think the posts variable may well contain threads.
  3. Marcus

    Marcus Well-Known Member

    I want xenforo to replace all existing /posts/ links with /threads/. This is how I think it's possible. Please give me some help if someone knows more about that:

    Overwrite XenForo_Route_Prefix_Posts::buildLink with that from XenForo_ControllerPublic_Post::actionIndex and ::getPostSpecificRedirect:

    class XenForo_Route_Prefix_Posts implements XenForo_Route_Interface
    public function 
    buildLink($originalPrefix$outputPrefix$action$extension$data, array &$extraParams)
    $ftpHelper XenForo_ControllerPublic_Thread::getHelper('ForumThreadPost');
    $post$thread$forum) = $ftpHelper->assertPostValidAndViewable($postId);
    $page floor($post['position'] / XenForo_Application::get('options')->messagesPerPage) + 1;
    XenForo_Link::buildPublicLink('threads'$thread, array('page' => $page)) . '#post-' $post['post_id'];
    I get this error: "Fatal error: Call to undefined method XenForo_Route_Prefix_Posts::getModelFromCache() in C:\Users\xy\Documents\xenforo\library\XenForo\ControllerHelper\ForumThreadPost.php on line 131"

    This is line 131:
    public function getPostOrError($postId, array $fetchOptions = array())
    LINE 131$post $this->_controller->getModelFromCache('XenForo_Model_Post')->getPostById($postId$fetchOptions); 
  4. nrep

    nrep Well-Known Member

    Hi Marcus,

    Did you make any progress with this? I'm trying to do the same thing, but haven't found an easy way to do it.
  5. Marcus

    Marcus Well-Known Member

    I abandoned this project. There is a complete code to do that anywhere here on this community if I remember correctly.
  6. nrep

    nrep Well-Known Member

    Thanks for the reply Marcus, I've had a good look on the forums, but can't find it. If you happen to stumble across it or know who made it, I'd be very grateful to know.

Share This Page