Jump to content
Larry Ullman's Book Forums

Creating A Forum In Yii


Recommended Posts

I'm starting to get to grips with Yii at last and am finding making progress slow. I've offered to build a forum for a network of local sports teams to let me dabble in Yii with no deadline pressures. I've read most of Agile Web Application Development endorsed by Yii and your blog articles on it but am still struggling. I used the forum schema from PHP 5 and MySQL 6 ed 3 adding a clubs model which sits above the users model and made a few adjustments to fields.

 

I've used Gii to create models and CRUD functionality. In the forum chapter of your book you basically accept a post and then check for a thread/topic ID - if it's not present you create one. I can't quite get my head round how to achieve this.

 

My best guess so far is to add a property to the PostsController called $_topic and then create a filter inside the PostsController that's called prior to the actionCreate method. In there I'd check for a topic ID in the POST array - if it exists assign it to the property if not do something like:

 

$topic = new Topics;

$topic->topic_title=$_POST['title'];
if($topic->save()){
    $this->_topic = $topic->getPrimaryKey();
} else {
    // Throw exception
}

 

Is that along the right lines? Any general pointers on what I need to do to create a forum greatly appreciated too. The book isn't the best (how long until your Yii book will be done Larry?) and the docs are only useful once you've got a little more experience.

 

Thanks

Link to comment
Share on other sites

I've heard similar comments about those books; haven't seen them myself. And, yes, the manual isn't too approachable for beginners. I'm hoping to work on a Yii book at the end of the year, thanks for asking.

 

If you base this upon the schema in the book, then the POST model would already have a topic_id property (or a theme_id or a forum_id, depending upon which exact schema). In the controller, I would start by creating a new POST instance, based upon the form data. If that resulting object already has a topic_id (or whatever) property value, then you know it's a reply and it can be saved. If not, then the controller just has to create the corresponding new Topic model and assign to the POST->topic_id property the value just created.

Link to comment
Share on other sites

 Share

×
×
  • Create New...