13: 附录

这些附录提供了与生产发布相匹配的简洁示例。

13.1: 带有视图的基本路由

prop title = '欢迎'

route both GET => view($this)

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

13.2: 带有变量的 route

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

method product($id){
    $record = product::record(id: $id) ?? http_response_code(404)
    view($this->productView, $record)
}

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

13.3: 异步表单

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

method send {
    %payload->name || error('姓名是必需的')
    return ['html' => ['#status' => '已发送']]
}

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

13.4: 最小的 app.json

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

13.5: 开发入口点

<?php
require('/srv/phlo/phlo.php');
phlo_app (
    id: '示例',
    host: 'dev.example.nl',
    auth: true,
    build: true,
    debug: true,
    app: '/srv/example.nl/',
    data: '/srv/example.nl/data/',
);

13.6: 发布入口点

<?php
require('/srv/phlo/phlo.php');
phlo_app (
    id: '示例',
    host: 'example.nl',
    app: '/srv/example.nl/release/',
    php: '/srv/example.nl/release/',
    data: '/srv/example.nl/data/',
);

我们使用必要的cookie来使该网站正常工作。在您的许可下,我们还使用分析工具来改善网站。