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 users


Now, we are going to create a function to list all users.

This one is even simpler than listing posts because it has no relations.

   public static function listUsers()
   {
      Lib.print("Users:<br/>");
      for(u in hxBlog.User.manager.all(false))
      {
         Lib.print(u.username+"<br/>");
      }
   }

Our class now looks like the following:

#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 options =   { 
                     user : "root",
                     pass : "root",
                     socket : null,
                     host : "127.0.0.1",
                     port : 8889,
                     database : "hxBlog"
            };
      connection...