-
-
Notifications
You must be signed in to change notification settings - Fork 5
Page views
A page view is the HTML that represents the response sent back to the browser. It stays as HTML on disk rather than being assembled from PHP string output.
That separation is important because it means the page can be designed, read, and reviewed as a document in its own right.
The simplest useful page view is just a normal HTML file. We can open it in an editor, write the structure we want, and serve it immediately.
That is helpful while prototyping because the first version of a page can be built and discussed as plain markup. Later, the same file can become production code by adding page logic, components, partials, and binding.
Default placeholder content can stay in the HTML too. Later, when data is bound into the document, those default values can be replaced. Until then, the file can still read well and make sense on its own.
For example:
<h1>User profile</h1>
<p>Display name: <span data-bind:text="displayName">none given</span></p>If there is no displayName bound to the HTML, the page displays the default message "none given", just as it would do without using a framework.
When a request matches a route, WebEngine loads the matching view file from page/. In many cases that is just one file, but a full response may also include:
- inherited layout through page partials
- shared framing through headers and footers
- reusable fragments through custom HTML components
Those features still result in one final HTML document, but they allow the source views to stay smaller and easier to maintain.
Keep page views semantic and readable. Write the HTML so another developer can understand the page structure without needing to read the PHP first.
It also helps to design the page shape before adding logic. Once the structure is visible in HTML, it is much easier to decide which parts need binding, which parts need reusable components, and which parts should stay static.
There are three methods of connecting a view to its logic:
-
data-bindattributes in HTML - this allows automatic hydration of pages where the HTML defines the shape and PHP defines the data, binding data to the DOM automatically. - Form
dobuttons - if a button has the namedo, its value is used to execute a PHP function when clicked. This is covered in page logic. - Direct DOM manipulation of the page from PHP.
When views need to be made dynamic, we'll use page logic.
- 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