PHPackages                             tbolner/flex-php-router - 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. [CLI &amp; Console](/categories/cli)
4. /
5. tbolner/flex-php-router

ActiveLibrary[CLI &amp; Console](/categories/cli)

tbolner/flex-php-router
=======================

Router for web and CLI applications (PHP).

1.0.3(5y ago)18.2k—0%1Apache-2.0PHPPHP &gt;=7.1

Since Jan 23Pushed 5y ago1 watchersCompare

[ Source](https://github.com/bolner/FlexPhpRouter)[ Packagist](https://packagist.org/packages/tbolner/flex-php-router)[ RSS](/packages/tbolner-flex-php-router/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)DependenciesVersions (5)Used By (0)

FlexPhpRouter
=============

[](#flexphprouter)

Simple and flexible router library for web and command line applications.

Packagist page:

Recommended IDE: [PhpStorm](https://www.jetbrains.com/phpstorm/)

Installation
------------

[](#installation)

Include the library in the *composer.json* file of your project:

```
{
    "require": {
        "tbolner/flex-php-router": "dev-master"
    }
}
```

Then execute:

```
composer update

```

This library requires PHP 7.1 or newer.

Usage example for web applications
----------------------------------

[](#usage-example-for-web-applications)

Create a folder in your project, to contain the controllers. For example:

```
project1/src/Controller/

```

Then create the controllers. The file name has to match the first part of the URI:

Example URLController pathGET project1/src/Controller/items.phpPOST project1/src/Controller/items.phpPUT project1/src/Controller/items.phpDELETE project1/src/Controller/testCtr4.phpGET [http://host/test+\_Ctr%255/qwerty/66](http://host/test+_Ctr%255/qwerty/66)project1/src/Controller/test\_Ctr5.phpGET project1/src/Controller/test-Ctr6.phpAs you see all special characters are removed from the first part of the URI when looking up the corresponding PHP file. (For security considerations.) To be precise: all characters are removed from the first part, which are not: a-z, A-Z, 0-9, - (dash), \_ (underline). (Other parts of the URL are unaffected by this mechanism.)

The controller will match for patters to decide what to execute. These matching parts are called "actions".

**project1/src/Controller/items.php**

```
