Download the PHP package folded/routing without Composer
On this page you can find all versions of the php package folded/routing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download folded/routing
More information about folded/routing
Files in folded/routing
Package routing
Short Description Routing functions for your web application.
License MIT
Informations about the package routing
folded/routing
Routing functions for your web application.
Summary
- About
- Features
- Requirements
- Installation
- Examples
- Version support
About
I created this library to have a standalone, fully featured router, and be able to pull it in any project, that have some existing code or not.
Folded is a constellation of packages to help you setting up a web app easily, using ready to plug in packages.
- folded/action: A way to organize your controllers for your web app.
- folded/config: Configuration utilities for your PHP web app.
- folded/crypt: Encrypt and decrypt strings for your web app.
- folded/exception: Various kind of exception to throw for your web app.
- folded/history: Manipulate the browser history for your web app.
- folded/http: HTTP utilities for your web app.
- folded/orm: An ORM for you web app.
- folded/request: Request utilities, including a request validator, for your PHP web app.
- folded/session: Session functions for your web app.
- folded/view: View utilities for your PHP web app.
Features
- register GET and POST routes actions (using callback)
- can match the current browsed URL and execute the associated callback
- can name the registered route to use additional functions like:
- getting the URL from a route name
Requirements
- PHP version 7.4+
- Composer installed
Installation
- 1. Install the package
- 2. Bootstrap the router
1. Install the package
On your project root directory, run this command:
2. Bootstrap the router
In the script that is called first, register your routes, and then call for matchRequestedUrl()
:
Examples
As this library is using nikic/fast-route internally, refer to this documentation to know all the possibilities regarding constructing the route string.
- 1. Register a GET route
- 2. Register a POST route
- 3. Catching url not found exceptions
- 4. Catching method not allowed exceptions
- 5. Naming a route
- 6. Get the URL of a named route
- 7. Redirect to a named route
- 8. Redirect to an URL
- 9. Check if the current URL is the given one
- 10. Check if a route matches the current URL
1. Register a GET route
In this example, we will register a GET route.
2. Register a POST route
In this example, we will register a POST route.
3. Catching url not found exceptions
In this example, we will catch a not found exception.
4. Catching method not allowed exceptions
In this example, we will catch a method not allowed error (which happens when you browsed an URL, but this url has been registered with another protocol).
5. Naming a route
In this example, we will name a route.
6. Get the URL of a named route
In this example, we will get the name of a named route.
7. Redirect to a named route
In this example, we will redirect to the URL of a named route.
By default, a status code 303
will be used alongside the redirection. You can override this behavior by adding the HTTP status code of your choice as second parameter:
8. Redirect to an URL
In this example, we will redirect to a plain URL.
By default, a status code 303
will be used alongside the redirection. You can override this behavior by adding the HTTP status code of your choice as second parameter:
9. Check if the current URL is the given one
In this example, we will check if the current url is the one we have in parameter.
10. Check if a route matches the current URL
In this example, we will check if a given route name matches the URL.
Note that if your route contains named parameter, for example /user/{user}
, you can use the second parameter to fill the named parameter with the actual value.
Version support
7.3 | 7.4 | 8.0 | |
---|---|---|---|
v0.1.0 | ❌ | ✔️ | ❓ |
v0.1.1 | ❌ | ✔️ | ❓ |
v0.1.2 | ❌ | ✔️ | ❓ |
v0.1.3 | ❌ | ✔️ | ❓ |
v0.2.0 | ❌ | ✔️ | ❓ |
v0.3.0 | ❌ | ✔️ | ❓ |
v0.4.0 | ❌ | ✔️ | ❓ |
v0.4.1 | ❌ | ✔️ | ❓ |
v0.5.0 | ❌ | ✔️ | ❓ |
v0.5.1 | ❌ | ✔️ | ❓ |
v0.6.0 | ❌ | ✔️ | ❓ |
All versions of routing with dependencies
nikic/fast-route Version 1.*
folded/exception Version 0.4.*
folded/http Version 0.1.*