• 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?

Marcus

Well-known member
#1
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.
 

Chris D

XenForo developer
Staff member
#2
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.
 

Marcus

Well-known member
#3
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:

PHP:
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');
list($post, $thread, $forum) = $ftpHelper->assertPostValidAndViewable($postId);
 
$page = floor($post['position'] / XenForo_Application::get('options')->messagesPerPage) + 1;
 
return 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:
PHP:
public function getPostOrError($postId, array $fetchOptions = array())
{
  LINE 131: $post = $this->_controller->getModelFromCache('XenForo_Model_Post')->getPostById($postId, $fetchOptions);
 

nrep

Well-known member
#4
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.
 

Marcus

Well-known member
#5
I abandoned this project. There is a complete code to do that anywhere here on this community if I remember correctly.
 

nrep

Well-known member
#6
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.