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

[Solved] Getting a reference to a node (forum) from its ID

Discussion in 'XenForo Development Discussions' started by hqarrse, Jan 6, 2014.

  1. hqarrse

    hqarrse Active Member

    I am trying to add some fields to the RSS feed, initially the forum name, by using the Zend RSS setDescription method.

    A problem I have is that the $thread object used to create the RSS entry contains a mass of information, including the node id, but not the node title:

    [thread_id] => 208234
    [node_id] => 29
    ......
    ....
    ....
    [node_title] =>
    [node_name] =>

    I'm new to XF and am not a PHP developer so my best attempt at getting the missing title and adding it to the feed is (in XenForo/ViewPublic/Forum/GlobalRss.php):

    PHP:
     $forum_model = new XenForo_Model_Forum();
                            
    $forum $forum_model->getForumById($thread['node_id']);
                            
    $entry->setDescription($forum['title']);
    This works perfectly well, but seems to me very heavyweight. Instantiating a Forum Model and a Forum just to get a title seems wrong.

    Can anyone tell me a better way of doing this?

    Thanks
     
  2. hqarrse

    hqarrse Active Member

    the correct method seems to be:

    $forum_model = XenForo_Model::create('XenForo_Model_Forum');
    .....
    RSS loop:
    {
    ....

    $forum=$forum_model->getForumById($thread['node_id']);
    $entry->setDescription($forum['title']);
    ...
    }
     

Share This Page