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 – 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;
import php.db.Manager;
import php.Web;
import php.Lib;
#end

class HxBlog
{
   public static function main(): Void
   {
      var connection : Connection;
      
 
     var...