You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/08.routes-and-controllers/03.front-controller/docs.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,9 +6,9 @@ taxonomy:
6
6
category: docs
7
7
---
8
8
9
-
The front controller is a collective term for the **routes** that your web application defines for its various **endpoints**. This is how UserFrosting links urls and methods to your application's code.
9
+
The front controller is a collective term for the **routes** that your web application defines for its various **endpoints**. This is how UserFrosting links URLs and methods to your application's code.
10
10
11
-
Sprinkles define their routes in classes and register them in their Recipe. There are two ways to define a route - as a closure, or as a reference to a [controller class](/routes-and-controllers/controller-classes) method. We will use a simple closure example here to illustrate the concept, but for your application **you should create controller classes**.
11
+
Sprinkles define their routes in classes and register them in their Recipe. There are two ways to define a route - as a closure, or as a reference to a [controller class](/routes-and-controllers/controller-classes) method. We will use a simple closure example here to illustrate the concept, but for your application,**you should create controller classes**.
12
12
13
13
The following is an example of a `GET` route:
14
14
@@ -30,10 +30,10 @@ $app->get('/api/users/u/{username}', function (string $username, Request $reques
30
30
31
31
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.
32
32
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.
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.
34
34
35
-
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.
35
+
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.
36
36
37
37
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).
38
38
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).
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 [PHP-DI Slim's Bridge Documentation](https://php-di.org/doc/frameworks/slim.html#why-use-php-dis-bridge).
0 commit comments