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 – Branching it with the main function


Now, let's just add some code to act depending on the action GET parameters and get all parameters as needed by the action and pass them to our functions:

  //Depending on the action GET parameter to do things:
  switch(Web.getParams().get("action"))
  {
     case "listPosts":
        listPosts();
     case "addUser":
        createUser(Web.getParams().get("login"), Web.getParams().get("password"));
     case "listUsers":
        listUsers();
     case "addPost":
        createPost(Web.getParams().get("author"), Web.getParams().get("title"), Web.getParams().get("body"));
     default:
        listPosts();
  }

Therefore, our complete class is as follows:

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