O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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;
}

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required