Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Forum Module /

Discuss the Forum Module.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Create new thread automatically from onAfterWrite() of another page?


Go to End


2 Posts   5003 Views

Avatar
madr

Community Member, 2 Posts

20 December 2010 at 4:34am

Hi,

I am currently building a Comic page in SilverStripe and I wish to handle reader comments via the Forum module.

I have a ComicPage and AFAIK it is the onAfterWrite() function I should use to create the initial forum thread, with a check to make sure I only create one thread per ComicPage.

I haven't succeeded in creating a post, though. Is there a simple way of doing this?

Avatar
Willr

Forum Moderator, 5523 Posts

20 December 2010 at 5:06pm

If you're using Forum trunk there is a couple things you need to do

$thread = new ForumThread();
$thread->Title = "Title";
$thread->ForumID = ID OF THE FORUM
$thread->write();

// create the post
$post = new Post();
$post->Content = "hi";
$post->AuthorID = Member::currentUserID();
$post->ThreadID = $thread->ID;
$post->ForumID = $thread->ForumID();
$post->write();

ID of the forum is the one thing you'll need to set.