Jump to:

1030 Posts in 805 Topics by 311 members

Forum Module

SilverStripe Forums » Forum Module » Create new thread automatically from onAfterWrite() of another page?

Discuss the Forum Module.

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

Page: 1
Go to End
Author Topic: 4010 Views
  • madr
    Avatar
    Community Member
    2 Posts

    Create new thread automatically from onAfterWrite() of another page? Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Create new thread automatically from onAfterWrite() of another page? Link to this post

    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.

    4010 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.