PHPackages                             brtriver/slim3-controller - 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. brtriver/slim3-controller

ActiveLibrary

brtriver/slim3-controller
=========================

Anonymous controller and trait class for Slim3

v0.1(10y ago)522MITPHPPHP &gt;=7.0

Since Jan 1Pushed 10y ago1 watchersCompare

[ Source](https://github.com/brtriver/slim3-controller)[ Packagist](https://packagist.org/packages/brtriver/slim3-controller)[ RSS](/packages/brtriver-slim3-controller/feed)WikiDiscussions master Synced 2mo ago

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

Slim3-controller
================

[](#slim3-controller)

[![Build Status](https://camo.githubusercontent.com/4ec8cce976c779a05bdb5b86c98afd7bac80cd6fafc0a167989f565409277805/68747470733a2f2f7472617669732d63692e6f72672f62727472697665722f736c696d332d636f6e74726f6c6c65722e737667)](https://travis-ci.org/brtriver/slim3-controller)

Anonymous controller and trait for Slim3 with PHP7. We can use anonymous classes in PHP7. So I use anonymous classes instead of anonymous functions. Slim3 now supports PSR-7 interfaces for its Request and Response objects. And Slim3 uses extends objects, and use it in your anonymous functions.

But we use Request and Response object directly, so I try to use anonymous classes to write controller action logic and it is to be readability. [read more](http://brtriver.hatenablog.com/entries/2016/01/02)

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

[](#requirements)

- PHP 7.0 or later.
- Slim3

Install
-------

[](#install)

install via composer

```
composer require brtriver/slim3-controller

```

Usage
-----

[](#usage)

you can read [example code](https://github.com/brtriver/slim3-controller/blob/master/examples/web/index.php).

sample code is blow:

```
use Brtriver\Controller\Controller;

$app->get('/hello/{name}', new class($app) extends Controller {

        public function action($args)
        {
            return $this->render($this->container['greet'] . $args['name']);
        }
});

```

- Controller class has these methods and class properties.
    - methods:
        - action($args): you should write your controller logic in this method.
        - render($output): helper method to render the $output with 200 status
        - render404($output): helper method to render the $output with 404 status
    - properties:
        - $this-&gt;request
        - $this-&gt;response
        - $this-&gt;app
        - $this-&gt;container

If use Template engine (PHP or Twig etc...), a renderWithT method in Templatable trait is available:

```
use Brtriver\Controller\Controller;
use Brtriver\Controller\Templatable;
$app->get('/hello/{name}', new class($app) extends Controller {
        use Templatable;

        public function action($args)
        {
            return $this->renderWithT('web.html', ['name' => $args['name']]);
        }
});

```

If use JSON response, a renderWithJson method in JsonResponse trait is available:

```
use Brtriver\Controller\Controller;
use Brtriver\Controller\JsonResponse;
$app->get('/json/{name}', new class($app) extends Controller {
	    use JsonResponse;

        public function action($args)
        {
            return $this->renderWithJson(['name' => $args['name']]);
        }
});

```

License
-------

[](#license)

slim3-controller is licensed under the MIT license.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

3786d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8833660f7d5586520ef2b32f3e91c2a8cd08e260fe02150535a882d8dc6ba14?d=identicon)[brtriver](/maintainers/brtriver)

---

Top Contributors

[![brtriver](https://avatars.githubusercontent.com/u/111285?v=4)](https://github.com/brtriver "brtriver (7 commits)")

### Embed Badge

![Health badge](/badges/brtriver-slim3-controller/health.svg)

```
[![Health](https://phpackages.com/badges/brtriver-slim3-controller/health.svg)](https://phpackages.com/packages/brtriver-slim3-controller)
```

###  Alternatives

[phlak/directory-lister

PHP directory lister

2.5k1.4k](/packages/phlak-directory-lister)[oat-sa/tao-core

TAO core extension

66136.7k74](/packages/oat-sa-tao-core)[bacula-web/bacula-web

The open source web based reporting and monitoring tool for Bacula

1537.5k](/packages/bacula-web-bacula-web)[brandembassy/slim-nette-extension

19190.2k](/packages/brandembassy-slim-nette-extension)[docler-labs/codeception-slim-module

Codeception Module for Slim framework.

13178.0k1](/packages/docler-labs-codeception-slim-module)[egroupware/openid

EGroupware OpenID Connect / OAuth2 server

1226.8k2](/packages/egroupware-openid)

PHPackages © 2026

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