Designer preview with sample data
A page is two files: the PHP that gets the data and the template that shows it. A designer working on the template needs the data, but not the database, the login or the rest of the server behind it. Ask for the page with &padSample and PAD runs no PHP at all - not the page's, nor an _inits.php or _exits.php around it - and takes the variables from _samples/<page>.json in the page's directory instead.
|
PHP fragments/samples_1.php |
HTML fragments/samples_1.pad |
Result |
|---|---|---|
|
|
Orders, as the real page sees them:
|
Beside that page lies fragments/_samples/samples_1.json:
{ "who": "a designer", "orders": [ { "number": 1, "total": 9.5 } ] }
so ?fragments/samples_1&padSample shows that order instead - from this machine only, see below.
Capturing a sample
-
?orders&padSample=capturerenders the page for real and writes the variables its PHP made toDATA/samples/<app>/orders.json, where the preview finds them too. -
apps/cli/pad sample shop ordersdoes the same from the shell, into the application's own_samples/orders.json, to commit with the template. Read it first: it holds whatever the page read.
Database tags in the template
A database tag in the template still asks the database, unless it has a name the sample holds: {array "* from orders", name='orders'} reads the sample's orders, and a capture records the database's answer under that name.
Who may ask
Skipping the PHP skips the checks it makes, so $padSample decides: 'local', the default, honours padSample for a request this machine makes to itself; TRUE for everyone - only on a design server without real data behind it; FALSE never. A capture is always local only.