Skip to content

Commit 50bb859

Browse files
committed
Add info on routes placeholders
1 parent 3ed80aa commit 50bb859

File tree

2 files changed

+3
-2
lines changed
  • pages
    • 08.routes-and-controllers/03.front-controller
    • 22.upgrading/01.46-to-50/02.guide

2 files changed

+3
-2
lines changed

pages/08.routes-and-controllers/03.front-controller/docs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ $app->get('/api/users/u/{username}', function (string $username, Request $reques
3030

3131
This is a very simplified example, but it illustrates the main features of a route definition. First, there is the call to `$app->get()`. The `get` refers to the HTTP method for which this route is defined. You may also define `post()`, `put()`, `delete()`, `options()`, and `patch()` routes.
3232

33-
The first parameter is the url for the route. Routes can contain placeholders such as `{username}` to match arbitrary values in a portion of the url. These placeholders can even be matched according to regular expressions: see the [Slim documentation ](https://www.slimframework.com/docs/v4/objects/routing.html#route-placeholders) for a complete guide to url placeholders.
33+
The first parameter is the url for the route. Routes can contain placeholders such as `{username}` to match arbitrary values in a portion of the url. These placeholders can even be matched according to regular expressions: see the [Slim documentation ](https://www.slimframework.com/docs/v4/objects/routing.html#route-placeholders) and [PHP-Di Slim's Bridge Documentation](https://php-di.org/doc/frameworks/slim.html#route-placeholder-injection) for a complete guide to url placeholders.
3434

3535
After the url comes the **closure**, where we place our actual route logic. In this example, the closure uses three parameters - a **placeholder** variable, the **request** object (which contains all the information from the client request) and the **response** object (which is used to build the response that the server sends back to the client). These parameters can vary from route to route. Behind the scenes, PHP-DI will intelligently inject the proper services and variables into the closure--more on that in a bit.
3636

3737
In the example above, we use the `username` placeholder to look up information for that user from the database. We then use the value of the `format` query parameter from the request to decide what to put in the response. You'll notice that the closure writes to the body of the `$response` object before returning. Slim will return the response to the client, perhaps first modifying it further through the use of [middleware](/advanced/middlewares).
3838

39-
For a more detailed guide to routes, we highly recommend that you read the [Slim documentation](https://www.slimframework.com/docs/v4/objects/routing.html).
39+
For a more detailed guide to routes, we highly recommend that you read the [Slim documentation](https://www.slimframework.com/docs/v4/objects/routing.html) and and [PHP-Di Slim's Bridge Documentation](https://php-di.org/doc/frameworks/slim.html#why-use-php-dis-bridge).

pages/22.upgrading/01.46-to-50/02.guide/docs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ Simple changes have been made to controller classes:
272272
3. `use Slim\Http\Response;` must be changed to `use Psr\Http\Message\ResponseInterface as Response;`
273273
4. Since the DI container is not available globally in the controllers, the services you require must be [injected via the constructor](/routes-and-controllers/controller-classes#service-injection).
274274
1. For example, to use the `view` service, inject `Slim\Views\Twig`.
275+
5. Routes placeholder, usually in the `$args` variables, should now [be directly injected](https://php-di.org/doc/frameworks/slim.html#route-placeholder-injection). See [Retrieving URL Parameters](https://learn.userfrosting.com/routes-and-controllers/client-input#retrieving-url-parameters) for more information.
275276

276277
See the [Controller classes](/routes-and-controllers/controller-classes) guide for more information.
277278

0 commit comments

Comments
 (0)