-
-
Notifications
You must be signed in to change notification settings - Fork 5
Page logic
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.
Like page views, page logic files are discovered from the URL. A request to /about can use:
page/about.htmlpage/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.
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 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.
If present, the hooks run in this order:
go_before- matching
do_* gogo_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.
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.
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.
- File-based routing
- Page views
- Page logic
- Dynamic URIs
- Headers and footers
- Custom HTML components
- Page partials
- Binding data to the DOM
- DOM manipulation
- Hello You tutorial
- Todo list tutorial
- Address book tutorial WIP
- Blueprints
- Application architecture
- Coding styleguide WIP
- PHP environment setup WIP
- Web servers WIP
- Background cron tasks
- Database setup WIP
- Client-side compilation WIP
- Testing WebEngine applications WIP
- Production checklist WIP
- Security WIP