Skip to content
Greg Bowler edited this page May 11, 2026 · 3 revisions

Page logic is the PHP entry point for one page request. Its job is to respond to the request, coordinate the application code that does the real work, and prepare the final page response.

That makes it a good place for orchestration, but not a good place for large business rules. Those are better moved into application classes.

How logic pairs with a view

Like page views, page logic files are discovered from the URL. A request to /about can use:

  • page/about.html
  • page/about.php

The HTML file is the view. The PHP file is the logic. If there is no logic file, the page is simply static. That is completely valid and is often the right place to start.

Logic hooks

go functions

The go function is the standard entry point for a page. It runs during a normal request after WebEngine has prepared the request, response, service container, and view model.

In go, we usually read input, call application classes, and bind the results into the page.

Logic functions should not output anything directly. If you echo or dump debug output from page logic, WebEngine captures that output and sends it to the browser's developer console. That can be useful while debugging, but it is not how page content should be produced.

do functions

do functions are for named user actions. When a request includes a do value, WebEngine looks for a matching do_* function and runs it.

For example, if a form submits do=save-profile, WebEngine will look for:

function do_save_profile():void {
	// ...
}

This keeps actions explicit. Rather than one large page handler guessing what the user meant, each named action can have its own small entry point.

Order of execution

If present, the hooks run in this order:

  1. go_before
  2. matching do_*
  3. go
  4. go_after

When logic is assembled from multiple matching files, the ordering follows the router's assembly rules so the broader shared logic and the more specific page logic run in a predictable sequence. In practice, this means we can use shared logic without losing the obvious page-specific entry point.

What to do in page logic

Page logic is a good place to:

  • read input
  • call application classes or services
  • bind data to the document
  • redirect the browser
  • set headers or response state

Those are all request-level concerns.

What NOT to do in page logic

Avoid putting large business rules in the page file. Avoid raw SQL manipulation code. Avoid building HTML in strings. Avoid relying on echo for normal output.

Page logic works best when it is easy to scan. A good page file should make the request flow obvious at a glance.


Now the pages can have dynamic content, let's learn about dynamic URLs.

Clone this wiki locally