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—Listing posts

Now, let's create a function to list posts. This one is pretty easy:

public static function listPosts()
{
Lib.println("Listing posts:<br/>");
for(p in hxBlog.Post.manager.all(false))
{
Lib.print(p.title+"(posted on"+p.postedOn.toString() + "by"+p.author.username+")<br/>");
Lib.print(p.body+"<br/>");
}
}

As you can see, it simply prints information from every post.

Also, note that you can use the User object corresponding to the author directly. This is one of the most interesting parts of the SPOD system.

Therefore, our main class now looks like this:

#ifneko import neko.db.Connection; import neko.db.Mysql; import neko.db.Manager; import neko.Web; import neko.Lib; #end #ifphp import php.db.Connection; import php.db.Mysql; ...

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