Controllers are the glue between routes and data. WP SSR Framework provides three base classes —Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Ahondev/portfolio-v2/llms.txt
Use this file to discover all available pages before exploring further.
WebController, ApiController, and the CPTControllerInterface — each tailored to a different concern. Web controllers render the React SPA shell (or return pure JSON for client-side navigation), API controllers return structured JSON responses for REST endpoints, and the CPT interface enforces a consistent archive/single contract for Custom Post Type routes.
All three classes ultimately extend BaseController → Base, which provides the remember() transient cache helper and the service() dependency-injection accessor.
WebController
WebController extends BaseController and is the class every front-end controller should extend. Its single most important method is view().
view()
view() assembles the $__wp_data__ payload that is embedded in the HTML shell for React to consume, or — when the request contains ?json=1 — returns the same payload as raw JSON for SPA navigation.
What it does, step by step:
Collect Composer data
Calls
ComposerManager::getView($view) to fetch all data registered by Composers that target this view or the wildcard '*'. The composer data is merged into $data.Resolve SEO metadata
For page routes (no
$post), SEO fields (seo_title, seo_description, seo_keywords, seo_author) are read from WordPress post meta on the matching Page object. For CPT singles, the same fields are read as ACF properties directly from the EloquentCPT instance.Build the payload
Assembles a
$__wp_data__ array containing view, seo, data, and assets (Vite manifest entries).postView()
A thin shorthand for CPT single pages that swaps the argument order to make call sites read more naturally:
$this->view($view, $data, $post).
remember()
Inherited from Base. Wraps WordPress transients for easy controller-level caching:
Real controller examples
CPTControllerInterface
Any controller registered viaRoute::CPT() must implement CPTControllerInterface. The interface enforces two methods:
| Method | When called | $post value |
|---|---|---|
archive() | Exact match on the CPT base path, e.g. /blog | — (no argument) |
single() | Any sub-path, e.g. /blog/my-article | EloquentCPT instance, or null if the slug doesn’t match any published post |
ApiController
ApiController extends BaseController and is the base class for every REST endpoint handler. Its methods return plain PHP arrays; the WP REST API serialises them to JSON automatically.
success()
error()
validate()
Delegates to a request class for input validation and throws ValidationException on failure:
Real controller example
API controller methods always receive a
\WP_REST_Request $request instance as their first argument. Use $request->get_param('key') for body and query parameters alike, or $request->get_body_params() for raw POST body fields.