Getting Started (PHP)

A simple webpage with Haxe and PHP
You can also start developing websites very quickly with Haxe. Let's start with a simple HelloWorld sample. Put the following code in the file Index.hx :

Now we need to compile this sample and create the PHP files from it. Create index.hxml so it contains the following content inside :

You can now run the index.hxml by simply double-clicking on it on Windows, or, for other platforms, run the command Haxe index.hxml in a terminal.

If everything goes well, it should create a directory www that contains the generated files. You can configure your webserver to point the www folder to see the PHP code in action.

Web API
So far we've been only using the Haxe Generic API, available for all the targeted platforms. Now let's look at the ServerSide specific API, which is located into the package php. Modify your Index.hx file with the following content :

This will use the php.Lib.print function that prints some raw strings (without adding debug informations). It will print the parameters sent by the browser.

Recompile it by double-clicking the index.hxml again, and visit [] (assuming that your webserver is pointing the generated folder www). It will display the request parameters for the URL that are sent by the browser.

There is also a lot of useful functionality available in the /api/php/Web class.

Note that the php package tries to mimic as far as possible the neko one. This allows for easy switching from/to the two platforms