Working examples

Read the code.
Open the page.

Each example shows a complete file included in the starter. Read it, then open the page it makes.

A first page

Open the page
pages/examples/hello.phpView source
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>PHP Cornerstone - Hello, world</title>
</head>
<body>
    <h1>Hello, world.</h1>
    <p>This is a whole page. Make a file, and it has a URL.</p>
</body>
</html>

No layout or styling required. Just a complete HTML document in a PHP file.

A shared header & footer

Open the page
pages/examples/includes.phpView source
<?php
$title = 'One header. One footer. Your page.';
require __DIR__ . '/../../partials/example-header.php';
?>

<h1>A few familiar pieces.</h1>
<p>The header and footer are ordinary PHP includes.</p>
<p>Change either shared file, and every page using it changes too.</p>

<?php require __DIR__ . '/../../partials/example-footer.php'; ?>

The two shared files: header and footer. Both are ordinary PHP.

A little PHP

Open the page
pages/examples/greeting.phpView source
<?php
use function Cornerstone\escape;

$name = is_string($_GET['name'] ?? null) ? trim($_GET['name']) : '';
$title = 'A little PHP goes a long way.';
require __DIR__ . '/../../partials/example-header.php';
?>

<h1>Hello, <?= escape($name !== '' ? $name : 'friend') ?>.</h1>
<p>A query string, a variable, and a little HTML.</p>

<form method="get" action="<?= escape($site->url('/examples/greeting')) ?>">
    <label for="name">Your name</label>
    <input id="name" name="name" value="<?= escape($name) ?>" maxlength="80">
    <button type="submit">Say hello</button>
</form>

<?php require __DIR__ . '/../../partials/example-footer.php'; ?>

Try a name in the form. The value is escaped before it becomes HTML.

Simple redirects

See the destination
redirects.phpView source
<?php
return [
    '/hello' => '/examples/hello',
    '/temporary-hello' => ['to' => '/examples/hello', 'status' => 302],
];

An exact old-to-new mapping. Read the few rules.