Beginners Thread Creation

LPH

Flight Director
Staff member
Based on a post from the XenForo Official Developer Forums. Thread creation requires only a few lines of code.

PHP:
\XF::asVisitor($user, function() use ($forum, $title, $message)
{
    $creator = \XF::service('XF:Thread\Creator', $forum);
    $creator->setContent($title, $message);
    $creator->setPrefix($forum['default_prefix_id']);
    $creator->setIsAutomated();
    $creator->save();
});

The class Creator extends \XF\Service\AbstractService and provides setting the thread content, title, forum, and prefix.
 
Top