XF 2.1 New post/thread and pass user

Robert9

Well-known member
$user = $this->em()->find('XF:User', $thread->user_id);

=> i have that $user that i need


Code:
        $creator = $this->service('XF:Thread\Creator', $forum);
        $creator->setPerformValidations(false);
        $creator->setContent($title, $message);
        $creator->setPrefix($thread->prefix_id);
        $thread2 = $creator->save();

This code runs perfect for me; so dont care about $thread2 for example.

How can i add that $user for creating the new thread(and post)
Something like

$creator->setUser($user);
 
Last edited:
OK
setPrefix is possible, because
public function setPrefix($prefixId)

but how can is use setUser while
protected function setUser(\XF\Entity\User $user)
 
$user = $this->em()->find('XF:User', $thread->user_id);

=> i have that $user that i need


Code:
        $creator = $this->service('XF:Thread\Creator', $forum);
        $creator->setPerformValidations(false);
        $creator->setContent($title, $message);
        $creator->setPrefix($thread->prefix_id);
        $thread2 = $creator->save();

This code runs perfect for me; so dont care about $thread2 for example.

How can i add that $user for creating the new thread(and post)
Something like

$creator->setUser($user);
https://xenforo.com/community/threa...reator-to-create-a-thread.136250/post-1186156 I guess this is much better 🙂
 
Meanwhile i have solved it with fast updates, but this need three times; so thank you for the better method. I will try it in a minute.
 
Back
Top Bottom