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

Get haXe 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.