Here's what happens when a user requests your site that is running on the Wireframe framework:
- User requests an URL belonging to a Page on the site. ProcessWire figures out the basic requirements to fulfil the request: which page it is for, which template to use, which template file to use, etc. If the Alternate Template Filename points to the Wireframe bootstrap file (usually wireframe.php in the /site/templates/ directory) Wireframe gets bootstrapped and initiated (configured).
- After booting up, Wireframe first checks for redirects. If a matching redirect rule is found, user is redirected right away and the Wireframe execution flow is halted.
- Assuming that we get this far – i.e. there were no matching redirect rules – the View component gets initialized and the $view API variable is set to refer to the View object.
- Wireframe looks for a Controller class for the template of current Page. If one is found, it gets instantiated. The constructor method of the Controller class sets the Controller object up and calls its init() method.
- Wireframe selects the view file for the View component. Unless the view file is "default", the PageRenderNoCache Session variable is set to avoid accidentally caching the output of a temporary (or alternative) view file. The rules used for selecting the view script:
a) By default a view script called "default" is used.
b) If allow_get_view configuration setting has been enabled, GET parameters can be used to set the view script – but only to the extent allowed by said configuration setting.
c) If view script has been set programmatically (in Controller or a hook) that value is used instead.
- The bootstrap file calls the render() method of Wireframe, which in turn renders the Page using the 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, and views are always entirely up to you as the developer, 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.
The easiest way to find hookable methods is searching for "___" (three underscores) in the Wireframe source code, but here are some examples of where you might hook to:
- 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 extend the ProcessWire Wire object, you can also make your own controller methods hookable.