1: Instellen

In deze tutorial bouw je Phlo Poll: een kleine poll-app die vraagt "Welke stack wint?". Je begint met een lege map en eindigt met een gestylede, meertalige, realtime poll. Elk hoofdstuk voegt een laag toe: een route, een view, CSS, data, stemmen, async updates, vertalingen en live resultaten. In dit eerste hoofdstuk installeer je Phlo, schrijf je je eerste route en zie je deze in de browser.

1.1: Installeer met Docker

De snelste manier om Phlo uit te voeren is de officiële Docker-image. Het bevat PHP, de FrankenPHP-webserver en de Phlo-engine op /phlo. Scaffold een nieuwe app in ./app:

docker run -it -v $(pwd)/app:/app ghcr.io/q-ainl/phlo php /phlo/install.php /app

De installer stelt een paar vragen. Beantwoord ze als volgt:

App name: Poll
Host: localhost
Purpose (one line): Which stack wins?
Resources (comma-separated, empty for none): <druk op enter>
Create "Poll" in /app for host localhost? y

Laat de resources voorlopig leeg; je voegt ze toe wanneer de app ze nodig heeft. De installer genereert de projectstructuur (app.phlo, www/app.php, data/app.json) en eindigt met een schone build, zodat je altijd met een schone lei begint.

1.2: Start de server

Voer dezelfde afbeelding uit als een webserver:

docker run -p 80:80 -v $(pwd)/app:/app ghcr.io/q-ainl/phlo

Open http://localhost in je browser. Je ziet de tijdelijke startpagina met de app-naam en je eenregelige doel. Die pagina komt van de gestructureerde app.phlo, die al een route, een view en een stijlblok bevat. Laat het zoals het is; de poll krijgt zijn eigen bestand.

1.3: Your first route

Every .phlo file transpiles to exactly one PHP class, named after the file. Create app/poll.phlo (next to app.phlo) with one line:

route GET hello => view('Hello')

Three things to notice:

Routes from all files are collected automatically; the scaffolded app.phlo activates them with app::route(). Save the file and reload the browser: nothing breaks, the new route is just not built yet.

1.4: Build and check

In development (build: true) Phlo rebuilds changed sources on every request, so reloading the browser is usually enough. The CLI gives you the same build explicitly, plus a lint check. The CLI runs inside the container, because www/app.php points at the engine at /phlo:

docker run --rm -v $(pwd)/app:/app ghcr.io/q-ainl/phlo php /app/www/app.php build::run
docker run --rm -v $(pwd)/app:/app ghcr.io/q-ainl/phlo php /app/www/app.php build::lint

The first command prints the files it transpiled:

["*app.php","+poll.php","*classmap.php","*sourcemap.php"]

Run it again and it returns []: everything is built, nothing changed. build::lint must also return []; that means the transpiled PHP parses cleanly. From here on, the chapters write the short form php www/app.php build::run; prefix it with the Docker command above if you use the Docker setup.

Now open http://localhost/hello. The browser shows a minimal page with the text Hello. One line of Phlo, one route, one page. In the next chapter you replace it with a real view.

We gebruiken essentiële cookies om deze site te laten werken. Met uw toestemming gebruiken we ook analytics om de site te verbeteren.