13: Appendices

These appendices give compact examples that match the production release.

13.1: Basic route with a view

prop title = 'Welcome'

route both GET => view($this)

view:
<main>
	<h1>$this->title</h1>
</main>

13.2: Route with a variable

route both GET product $id => $this->product($id)

method product($id){
	if (!$record = product::record(id: $id)) return view('Product not found', code: 404)
	view($this->productView, $record)
}

view productView($record):
<article>
	<h1>$record->title</h1>
</article>

13.3: Async form

route both GET contact => view($this)
route async POST contact @name,email,message => $this->send

method send {
	%payload->name || error('Name is required')
	return ['html' => ['#status' => 'Sent']]
}

view:
<form method=post action="/contact" class=async>
	<input name=name>
	<input name=email>
	<textarea name=message></textarea>
	<button>Send</button>
</form>
<p#status/>

13.4: Minimal app.json

{
    "resources": [
        "payload",
        "session",
        "security/security",
        "security/token",
        "tag",
        "phlo.async",
        "DOM/form"
    ],
    "release": "%app/release/"
}

13.5: Dev entrypoint

<?php
require('/opt/phlo/phlo.php');
phlo_app (
	id: 'Example',
	host: 'dev.example.nl',
	auth: true,
	build: true,
	debug: true,
	app: '/var/www/example.nl/',
	data: '/var/www/example.nl/data/',
);

13.6: Release entrypoint

<?php
require('/opt/phlo/phlo.php');
phlo_app (
	id: 'Example',
	host: 'example.nl',
	app: '/var/www/example.nl/release/',
	php: '/var/www/example.nl/release/',
	data: '/var/www/example.nl/data/',
);

We use essential cookies to make this site work. With your permission we also use analytics to improve the site.