PHPackages                             dframe/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. [Framework](/categories/framework)
4. /
5. dframe/router

ActiveLibrary[Framework](/categories/framework)

dframe/router
=============

Router component Dframe

v4.2.0(3y ago)1381MITPHPPHP &gt;=7.3

Since Aug 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/dframe/router)[ Packagist](https://packagist.org/packages/dframe/router)[ Docs](https://dframeframework.com/en/docs/dframe/master/router/overview)[ RSS](/packages/dframe-router/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (12)Used By (1)

Dframe/Router - Component
=========================

[](#dframerouter---component)

[![Build Status](https://camo.githubusercontent.com/f83278d479229fb6e2b8bbe9180be5730ef3dae9dc0beb7e589f13350cd5652e/68747470733a2f2f7472617669732d63692e6f72672f646672616d652f726f757465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/dframe/router) [![Latest Stable Version](https://camo.githubusercontent.com/b06ebadc3121046c58b9184b4750c0ecc931a6efd198d1e2671f1cd76097b8ca/68747470733a2f2f706f7365722e707567782e6f72672f646672616d652f726f757465722f762f737461626c65)](https://packagist.org/packages/dframe/router) [![Total Downloads](https://camo.githubusercontent.com/f9ff6538124be77cbe487b48cc1d9c87ec3fbd94b85ef4963f6c92e3f2d02042/68747470733a2f2f706f7365722e707567782e6f72672f646672616d652f726f757465722f646f776e6c6f616473)](https://packagist.org/packages/dframe/router) [![Latest Unstable Version](https://camo.githubusercontent.com/c134cc8501066ec3c5b1bdbe0af6689e21ada89f1bfff2dfaaef0a8757f87c3a/68747470733a2f2f706f7365722e707567782e6f72672f646672616d652f726f757465722f762f756e737461626c65)](https://packagist.org/packages/dframe/router) [![License](https://camo.githubusercontent.com/cad61f3d7ef091db41239a3a7402844c317bb79b582936d4426c68c730bc0065/68747470733a2f2f706f7365722e707567782e6f72672f646672616d652f726f757465722f6c6963656e7365)](https://packagist.org/packages/dframe/router)

[![php framework dframe logo](https://camo.githubusercontent.com/fd0e41a4616aeae28318df2698482c0f1538928857ff531019f4481606ff8d2b/68747470733a2f2f646672616d656672616d65776f726b2e636f6d2f696d672f6c6f676f5f66756c6c2e706e67)](https://camo.githubusercontent.com/fd0e41a4616aeae28318df2698482c0f1538928857ff531019f4481606ff8d2b/68747470733a2f2f646672616d656672616d65776f726b2e636f6d2f696d672f6c6f676f5f66756c6c2e706e67)

### Documentation - [Router PHP](https://dframeframework.com/en/docs/dframe/master/router/overview)

[](#documentation---router-php)

### Composer

[](#composer)

```
$ composer require dframe/router
```

Simple PHP Router
-----------------

[](#simple-php-router)

Creating an application, it's worth taking care of their friendly links. Its has a big part in position in SEO. Link router work in a similar way as network router. It is responsible for calling the method from controller.

```
$this->router->addRoute([
'page/:method' => [
'page/[method]/',
'task=page&action=[method]'
]
]);
$this->router->makeUrl('page/:action?action=index'); // Return: https://example.php/page/index
$this->router->isActive('page/:action?action=index'); // Current Website true/false
```

Configuration
=============

[](#configuration)

We define the table with adresses for our application in the configuration file

- **|https|** - true/false forcing https
- **|NAME\_CONTROLLER|** - Name of the default controller
- **|NAME\_METHOD|** - Name of the default method from the controller in NAME\_CONTROLLER
- **|publicWeb|** - Main folder from which files will be read (js, css)
- **|assetsPath|** - Dynamic folder
- **|docs/docsId|** - Example routing with the |docsId| variable, which contains the |docs/\[docsId\]/| adress definition and the |task| parameters to which it's assigned.
- **|error/404|** - as above
- **|default|** - default definition loading the controller/method. |params| defines the possibility of additional parameters appearing, while

```
'_params' => [
'[name]/[value]/',
'[name]=[value]'
]
```

defines the way the additional foo=bar parameters should be interpreted.

**Config/router.php**

```

 return [
     'https' => false,
     'NAME_CONTROLLER' => 'page',    // Default Controller for router
     'NAME_METHOD' => 'index',       // Default Action for router
     'publicWeb' => '',              // Path for public web (web or public_html)

     'assets' => [
         'minifyCssEnabled' => true,
         'minifyJsEnabled' => true,
         'assetsDir' => 'assets',
         'assetsPath' => APP_DIR.'View/',
         'cacheDir' => 'cache',
         'cachePath' => APP_DIR.'../web/',
         'cacheUrl' => HTTP_HOST.'/',
     ],

     'routes' => [
         'docs/:page' => [
             'docs/[page]/',
             'task=Page&action=[page]&type=docs'
         ],

         'methods/example/:exampleId' => [
            'methods/example/[exampleId]',
            'methods' => [
                'GET' => 'task=Methods,Example&action=get&exampleid=[exampleId]',
                'POST' => 'task=Methods,Example&action=post&exampleid=[exampleId]',
            ]
         ],

         'error/:code' => [
             'error/[code]/',
             'task=Page&action=error&type=[code]',
             'code' => '([0-9]+)',
             'args' => [
                 'code' => '[code]'
             ],
         ],

        ':task/:action' => [
            '[task]/[action]/[params]',
            'task=[task]&action=[action]',
            'params' => '(.*)',
            '_params' => [
                '[name]/[value]/',
                '[name]=[value]'
            ]
        ],

         'default' => [
             '[task]/[action]/[params]',
             'task=[task]&action=[action]',
             'params' => '(.*)',
             '_params' => [
                 '[name]/[value]/',
                 '[name]=[value]'
             ]
         ]
     ]

 ];
```

Controller
----------

[](#controller)

- makeUrl - is used for generating the full adress. For example |makeurl| - method used for redirections, equivalent of |header| but with a parameter being a key from the Config/router.php table. In case of using docs/:docsld it looks as the following |redirect|

**Controller/Page.php**

```
 namespace Controller;

 use Dframe\Controller;
 use Dframe\Router\Response;

 class PageController extends Controller
 {

     /**
      * @return bool
      */
     public function index()
     {
         echo $this->router->makeUrl('docs/:docsId?docsId=23');
         return;
     }

     /**
      * @return mixed
      */
     public function docs()
     {

         if (!isset($_GET['docsId'])) {
             return $this->router->redirect('error/:code?code=404');
         }
     }

     /**
      * @param string $status
      *
      * @return mixed
      */
     public function error($status = '404')
     {
         $routerCodes = $this->router->response();

         if (!array_key_exists($status, $routerCodes::$code)) {
             return $this->router->redirect('error/:code?code=500');
         }

         $view = $this->loadView('index');
         $smartyConfig = Config::load('view/smarty');

         $patchController = $smartyConfig->get('setTemplateDir', APP_DIR . 'View/templates') . '/errors/' . htmlspecialchars($status) . $smartyConfig->get('fileExtension', '.html.php');

         if (!file_exists($patchController)) {
             return $this->router->redirect('error/:code?code=404');
         }

         $view->assign('error', $routerCodes::$code[$status]);
         return Response::create($view->fetch('errors/' . htmlspecialchars($status)))->headers(['refresh' => '4;' . $this->router->makeUrl(':task/:action?task=page&action=index')]);
     }

 }
```

View
----

[](#view)

assign - it's a method of the template engine that assignes value to a variable which is used in the template files.

**View/templates/index.html.php**

```
https://
```

Using only PHP

- |router| all already available methods used like in |page/index|

**View/index.php**

```
namespace View;

use Dframe\Asset\Assetic;

class IndexView extends \View\View
{

     /**
      * @return bool
      */
     public function init()
     {
         $this->router->assetic = new Assetic();
         $this->assign('router', $this->router);
     }
}
```

Dframe\\Router\\Response;
-------------------------

[](#dframerouterresponse)

Extention of the basic **Dframe\\Router** is **Dframe\\Router\\Response**, adding functionality of setting the response status (404, 500, etc.) and their headers.

```
return Response::create('Hello Word!')
    ->status(200)
    ->headers([
                  'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT',
                  'Cache-Control' => 'no-cache',
                  'Pragma',
                  'no-cache'
              ]);
```

For generating html.

Render json

```
return Response::renderJSON(['code' => 200, 'data' => []]);
```

Render json with callback

```
return Response::renderJSONP(['code' => 200, 'data' => []]);
```

Redirect

```
return Response::redirect(':task/:action?task=page&action=login');
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.4% 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 ~79 days

Recently: every ~68 days

Total

11

Last Release

1299d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/954f9b5cd3e021b52a7bb0cabe07b2d7763edf98485fe47cccf835124d79205c?d=identicon)[dusta](/maintainers/dusta)

---

Top Contributors

[![dusta](https://avatars.githubusercontent.com/u/9001348?v=4)](https://github.com/dusta "dusta (85 commits)")[![pawelkg](https://avatars.githubusercontent.com/u/1854055?v=4)](https://github.com/pawelkg "pawelkg (3 commits)")[![amadeuszxd](https://avatars.githubusercontent.com/u/9860313?v=4)](https://github.com/amadeuszxd "amadeuszxd (1 commits)")[![pajsmolinski](https://avatars.githubusercontent.com/u/9739792?v=4)](https://github.com/pajsmolinski "pajsmolinski (1 commits)")

---

Tags

phproutingphp-configdframe

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

712181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)[laravel/pail

Easily delve into your Laravel application's log files directly from the command line.

91545.3M590](/packages/laravel-pail)[nette/bootstrap

🅱 Nette Bootstrap: the simple way to configure and bootstrap your Nette application.

68535.8M592](/packages/nette-bootstrap)

PHPackages © 2026

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