Here's what happens when a user requests your site that is running on the Wireframe framework:
- When user requests an URL, ProcessWire figures out the basic requirements to fulfil the request: which page is it for, which template to use, which template file to use, etc. If "Alternate Template Filename" of the template in question points to Wireframe's bootstrap file (typically /site/templates/wireframe.php), Wireframe gets bootstrapped and initialized (configured).
- After booting up, Wireframe automatically checks for redirects (see configuration settings for more details). If a matching redirect rule is found, user is redirected right away, and the Wireframe execution flow is halted.
- If there were no matching redirect rules, the View component gets initialized, and the $view API variable is set to refer to this particular View object.
- Wireframe attempts to find a Controller class for current template. If a matching class is found, a Controller object gets instantiated, and the constructor method of the Controller class sets it up and calls its init() method.
- A view file is selected for the View component. Unless that view file is "default", the PageRenderNoCache Session variable is set to avoid accidentally caching the output of a temporary (or alternative) view file.
Rules used for selecting the view file:
a) By default a view file called "default" is used.
b) If "allow_get_view" configuration setting has been enabled, GET parameters can be used to set the view file – but only to the extent allowed by said configuration setting.
c) If a view file has been defined programmatically (in Controller or a hook), then that file is used instead.
- The Wireframe bootstrap file calls render() method of Wireframe, rendering the page using layout and view files provided for the View component, and finally outputs the resulting markup.
Modifying the program flow with hooks
The contents of Controllers, layouts, partials, components, and view files are always up to you (as the developer of the site), but if you need to dig a bit deeper and modify the program flow as well, you can do that by hooking into various points described above.
While it's quite easy to find hookable methods by searching for "___" (three underscores) in the Wireframe source code, here are some examples of where you might start from:
- Wireframe::init() for the earliest possible point in Wireframe execution. This is literally the first method that gets called when Wireframe is starting up.
- Wireframe::checkRedirects() for when Wireframe is looking for redirects. You can read more about the built-in redirect feature from the Configuration settings page.
- Wireframe::redirect() for when Wireframe has detected that a redirect should happen, and is performing said redirect.
- Wireframe::initView() for when the View object is being instantiated.
- Wireframe::initController() for when the Controller object is being instantiated.
- Wireframe::render() for when the page is being rendered. This is the method that renders layouts, views, and finally returns the rendered markup.
Note that since Controllers and Components ultimately derive from the ProcessWire Wire object, you can also make your own methods hookable.