-
-
Notifications
You must be signed in to change notification settings - Fork 5
File based routing
In WebEngine, routes are file-based. That means the URL is not usually defined in a central routing table. Instead, it maps directly to files and directories in the project.
This keeps routing obvious. If we know the URL, we can usually guess where the view and logic files live. If we know the file path, we can usually guess the URL.
The root URL / maps to page/index.html. A nested URL such as /about/team maps to page/about/team.html.
Directory-style URLs are also supported. That means a path can resolve through an index file inside a directory. For example:
-
/->page/index.html -
/blog->page/blog.htmlorpage/blog/index.html -
/blog/post->page/blog/post.html
It is best to avoid creating clashing paths such as both page/contact.html and page/contact/index.html, because that makes the route less obvious to the next developer reading the project.
Each route can have an HTML view file, a PHP logic file, or both. In the normal case:
-
page/about.htmlis the page view -
page/about.phpis the page logic
If only the HTML file exists, the page is static and can still be served perfectly well. If only the PHP file exists, there is no page view to render and the route is incomplete. WebEngine expects a view for a page response.
This pairing is one of the main shapes to get comfortable with. It lets the response be built from ordinary HTML first, with PHP added only when the page actually needs behaviour.
This model makes code navigation fast because there are fewer places to look. There is no need to search through a routing table before we can even find the page.
It also keeps more advanced features straightforward. Dynamic routes, shared headers and footers, components, and partials all build on top of the same idea that a path on the web should map cleanly to a path in the project.
Let's learn about HTML in page views, then we'll cover PHP in 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