Book Image

haXe 2 Beginner's Guide

5 (1)
Book Image

haXe 2 Beginner's Guide

5 (1)

Overview of this book

Table of Contents (21 chapters)
haxe 2
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – Adding a post


The function to create a post will have a little twist because it will have to set the author of the post. It will take, among other information, the name of the author. We will then retrieve the author's object by using the manager's search function.

   public static function createPost(authorLogin : String, title : String, body : String) : hxBlog.Post
   {
      var author = hxBlog.User.manager.search({username : authorLogin}, false).first();
      var p = new hxBlog.Post();
      p.author = author;
      p.title = title;
      p.body = body;
      p.postedOn = Date.now();
      p.insert();
      return p;
   }