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

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.