PHPackages                             badluck/badrouter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. badluck/badrouter

ActiveLibrary[Framework](/categories/framework)

badluck/badrouter
=================

A simple Sinatra inspired router class for PHP

v0.4.5(2y ago)4222MITPHPPHP &gt;=7.4.33

Since Apr 5Pushed 2y agoCompare

[ Source](https://github.com/BadLuckSoftware/BadRouter)[ Packagist](https://packagist.org/packages/badluck/badrouter)[ RSS](/packages/badluck-badrouter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (21)Used By (0)

BadRouter
=========

[](#badrouter)

A minimalist router inspired by Ruby's Sinatra router.

Visit the official documentation page here:

Install
=======

[](#install)

**1.** Run `composer require badluck/badrouter` in your project directory to install the package and its dependencies.

**2.** Require the autoloader. At the beginning of your PHP file, require the Composer autoloader by adding this line of code:

```
require_once('./vendor/autoload.php');
```

**3.** Use the `Router` static class.

You can use `::get`, `::post`, `::put`, and `::delete`. BadRouter supports dynamic routes in `{braces}`.

```
Router::get('/user/{id}', function ($id) {
  $locals = [
    "user_id" => $id
  ];
  Router::render('/user', $locals);
});
```

**4.** Configure the view and public directories.

The `public` directory is where the router will search for static files if the URI is not a route. The `views` directry is where `Router::render` will search when rendering pages.

```
Router::set_public('public');
Router::set_views('views');
```

**5.** After the router is configured, run it.

```
Router::run();
```

Full Usage example
==================

[](#full-usage-example)

```
