Php Express Router is a lightweight and flexible PHP routing library that allows you to easily handle HTTP requests and define routes for your web application.
To get started using Php Express Router, follow these steps:
Clone the repository or download the source code.
git clone https://github.com/Jobians/Php-Express-Router.git
Place the cloned files in your project directory:
your_project/
- core/
- modules/
- smarty/
- middlewares/
- static.php
- Request.php
- Response.php
- Router.php
server.php
.htaccess
The core/
directory contains essential router files and modules. The middlewares/
directory holds the built-in static middleware file.
Here are some usage examples to get you started:
require_once 'core/Router.php';
$router = new Router();
$router->get('/', function($req, $res) {
$res->send('Hello, World!');
});
$router->run();
You can configure the router using the set
method. This method allows you to customize various aspects of the router’s behavior. Here are the available configuration options:
$router->set('base_path', '/your-project');
'default'
(native PHP) and 'smarty'
.
$router->set('view_engine', 'smarty');
$router->set('views', '/views');
$router->set('template_cache_dir', '/cache');
$router->set('template_caching', true);
$router->set('static', '/public');
It’s important to set these configurations before defining routes and starting the router using the run
method. Configuration settings will affect the router’s behavior and how it handles requests.
For additional usage examples, check the examples folder in this repository. You’ll find more scenarios and use cases that can help you get a deeper understanding of how to use Php Express Router effectively.
If you find my work helpful, you can support me by donating:
Contributions are welcome! If you find any issues or want to add new features, feel free to submit a pull request.
This project is licensed under the MIT License.