In pre-v2021 versions, the generated application was file based, if you wanted to add a custom page, you added a Custom File so you can access, e.g. /mypage.php
. In v2021, routing is used, if you want a page with header and footer, you can still use Custom File with Include common files enabled so that PHPMaker will generate a route, e.g. /mypage
. However, if you just want to do an action on the server side and return the result (as text or JSON) without the layout (and other HTML), now there is an alternative way (and simpler way, depending on your usage), you can use the new Route_Action and/or Api_Action server event to add routes and/or API actions with or without parameters, e.g. in Route_Actions server event
$app->get('/books/{id}', function ($request, $response, array $args) {
$name = ExecuteScalar("SELECT name FROM books WHERE id = " . AdjustSql($args['id'])); // Get book info by $args['id'], here assume id is integer
$response->getBody()->write($name); // Write to response body
return $response; // Return the response
});
If you want to return JSON, read Returning JSON.
Also See How to create routes.