O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required