STARTING POINT
The browser makes a request.
GET /products/42 HTTP/1.1
Host: 127.0.0.1:8910
Accept: text/htmlGET is the HTTP method. /products/42 is the path. Accept indicates the desired format. PHPAML turns this raw information into a Request object so your code does not read PHP globals directly.
Six steps, six responsibilities.
- 1public/index.php
Receives Web requests and boots the application.
- 2Middleware
Apply security, session, or authentication before the action.
- 3Router
Matches the method and path against registered routes.
- 4Controller
Coordinates the requested use case.
- 5Model and view
Obtain data and build its representation.
- 6Response
Defines status, headers, and returned body.
What if nothing matches?
404Unknown routeNo registered path matches.
405Method not allowedThe path exists, but not for that HTTP method.
500Application errorThe route exists, but processing failed.
CHECK YOUR UNDERSTANDING
A GET /users route exists. What should POST /users return when no POST route is declared?
Show the answer
405 Method Not Allowed
SUMMARY
What to remember
- public/index.php boots the application.
- Middleware surrounds processing.
- The router uses method and path.
- Response always contains the final HTTP result.