PHPackages                             txiki/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. txiki/router

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

txiki/router
============

Simple router for PHP

1.0.1(11y ago)112MITPHPPHP &gt;=5.4.0

Since Feb 22Pushed 11y ago2 watchersCompare

[ Source](https://github.com/dieg0v/txiki-router)[ Packagist](https://packagist.org/packages/txiki/router)[ Docs](https://github.com/dieg0v/txiki-router)[ RSS](/packages/txiki-router/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

Txiki Router
============

[](#txiki-router)

Simple router for PHP

[![Author](https://camo.githubusercontent.com/a5910079994ad85d4382304bf54d9f52c7612ab28d1230b8f15ec4a8f1ede1b9/687474703a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d406469656730762d626c75652e7376673f7374796c653d666c61742d737175617265)](https://twitter.com/dieg0v)[![Latest Version](https://camo.githubusercontent.com/8580adef6f3675069c7b0b1d575e72b8c46c84b9239a07d342aed5fd7610d9fa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6469656730762f7478696b692d726f757465722e7376673f7374796c653d666c61742d737175617265)](https://github.com/dieg0v/txiki-router/releases)[![Packagist Version](https://camo.githubusercontent.com/9b6b1917acb74d75ea83e237fbd1b6ec4ee8be4e74491d781b144f79d7c5a69e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7478696b692f726f757465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/txiki/router)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/9487cdb9738793722dc58c0d45e508506fa385135bf75a1a09631986610c3ec2/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6469656730762f7478696b692d726f757465722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/dieg0v/txiki-router)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f9fa26a392980aedf6018078e13bcb48e09b18c58e84331502ee4e4d0a345d74/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6469656730762f7478696b692d726f757465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/dieg0v/txiki-router/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/35d60655f68e3fd9cc86d42cde6e150f0986e26fd8803b0e4d2941b1db29e32f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6469656730762f7478696b692d726f757465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/dieg0v/txiki-router/?branch=master)

Install
-------

[](#install)

Via Composer

```
$ composer require txiki/router
```

Requirements
------------

[](#requirements)

The following versions of PHP are supported by this version.

- PHP 5.4
- PHP 5.5
- PHP 5.6
- HHVM

Documentation
-------------

[](#documentation)

Simple example:

```
// load composer autoload
require '../vendor/autoload.php';

use Txiki\Router\Route;

$r = new Route();

// add GET route
$r->get('/home', function(){
    return "GET Hello world!";
});

//tell router what you want to process, the route and the http method
$route = $r->exec( '/home', 'get');

if($route!==false){
	// example process response
	echo $route->response;
}else{
	// example response 404
	echo '404';
}
```

Add more routes:

```
// add POST route
$r->post('/home', function(){
    return "POST Hello world!";
});

// add DELETE route
$r->delete('/home', function(){
    return "DELETE Hello world!";
});

// add PUT route
$r->put('/home', function(){
    return "PUT Hello world!";
});
```

Wildcard and custom routes:

```
// add route to any http method
$r->any('/home', function(){
    return "Hello world! respond to any http method";
});

// custom http methods for one route
$r->add('/home', function(){
    return "Hello world! respond to custom http methods";
}, 'get|post');
```

Manage custom url params:

```
$r->any('/test-{id}/{name}/{n}', function($id, $name , $n){
    return 'Test: ' . $id .' '.$name.' '.$n;
})->params([
		// add your own regular expression to param or
		// 'use Txiki\Router\RouteRegex'
		'id' => RouteRegex::INT,
		'name' => RouteRegex::ALPHA,
		'n' => RouteRegex::INT
	]
);
```

Use class/method as callback:

```
class myClass{
    public function method1( $id, $name){
        return 'Hello world ' .$id . ' '. $name;
    }
}

$r->get('/user/{id}/{name}', 'myClass::method1');
```

Helper methods:

```
// get all established routes
$table = $r->table();

// get all routes for '/home'
$map = $r->getRouteMap('/home');

// get only POST route for '/home'
$map = $r->getRouteMap('/home', 'post');
```

Testing
-------

[](#testing)

```
$ vendor/bin/phpunit
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/dieg0v/txiki-router/blob/master/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Diego Vilariño](https://github.com/dieg0v)
- [All Contributors](https://github.com/dieg0v/txiki-router/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/dieg0v/txiki-router/blob/master/LICENSE.md) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 88.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

2

Last Release

4099d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/870654?v=4)[Diego Vilariño](/maintainers/dieg0v)[@dieg0v](https://github.com/dieg0v)

---

Top Contributors

[![dieg0v](https://avatars.githubusercontent.com/u/870654?v=4)](https://github.com/dieg0v "dieg0v (40 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (5 commits)")

---

Tags

routerroutingtxiki

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/txiki-router/health.svg)

```
[![Health](https://phpackages.com/badges/txiki-router/health.svg)](https://phpackages.com/packages/txiki-router)
```

###  Alternatives

[bramus/router

A lightweight and simple object oriented PHP Router

1.1k458.8k49](/packages/bramus-router)[lord/laroute

Access Laravels URL/Route helper functions, from JavaScript.

8022.0M8](/packages/lord-laroute)[watson/active

Laravel helper for recognising the current route, controller and action

3253.6M14](/packages/watson-active)[wazum/sluggi

TYPO3 extension for URL slug management with inline editing, auto-sync, locking, access control, and redirects

39488.5k](/packages/wazum-sluggi)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
