PHPackages                             yaf/extras - 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. [Templating &amp; Views](/categories/templating)
4. /
5. yaf/extras

AbandonedArchivedLibrary[Templating &amp; Views](/categories/templating)

yaf/extras
==========

Extras package for the Yet Another Framework

v0.3.2(11y ago)202739MITPHPPHP &gt;=5.3.0

Since Oct 21Pushed 11y ago7 watchersCompare

[ Source](https://github.com/rhyzx/php-yaf-extras)[ Packagist](https://packagist.org/packages/yaf/extras)[ Docs](http://github.com/rhyzx/php-yaf-extras)[ RSS](/packages/yaf-extras/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (7)Used By (0)

Yaf Extras
==========

[](#yaf-extras)

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

[](#installation)

Install via Composer

```
> composer require "yaf/extras:*"
```

---

### Class: RESTfulRouter

[](#class-restfulrouter)

**RESTful** router, provide a quick way to register **RewriteRoute** with **HTTP method** adaptation(RESTful).

##### $router = new RESTfulRouter

[](#router--new-restfulrouter)

Create a router.

##### $router-&gt;on($method, $url, $controller, $action)

[](#router-onmethod-url-controller-action)

- $method **String**: HTTP method name, support wildcard `*` to match all methods.
- $url **String**
- $controller **String**: controller class name
- $action **String**: method name of controller

**Tips**. you can register multi methods in single `on()`, use space to separate methods, eg. `$router->on('get post', 'user/:id', 'user', 'show')`

##### Example

[](#example)

```
class Bootstrap extends \Yaf\Bootstrap_Abstract {
    // default YAF style route registration
    function _initRoute(\Yaf\Dispatcher $dispatcher) {
        $router = $dispatcher->getRouter();

        // default yaf rewrite route
        $router->addRoute('dog', new \Yaf\Route\Rewrite('dogs', array('controller' => 'dog', 'action' => 'index')));
        $router->addRoute('dog_show', new \Yaf\Route\Rewrite('dogs/:id', array('controller' => 'dog', 'action' => 'show')));
        $router->addRoute('dog_create', new \Yaf\Route\Rewrite('dogs/create', array('controller' => 'dog', 'action' => 'create')));
        $router->addRoute('dog_destroy', new \Yaf\Route\Rewrite('dogs/:id/delete', array('controller' => 'dog', 'action' => 'destroy')));
    }

    // RESTful style
    function _initRESTfulRoute() {
        $router = new \Yaf\Extras\RESTfulRouter;
        $router->on('post', 'cat', 'cat', 'create');
        $router->on('get', 'cat/:id', 'cat', 'show');
        $router->on('delete', 'cat/:id', 'cat', 'destroy');

        $router->on('put patch', 'cat/:id', 'cat', 'update');

        $router->on('*', 'pig/:id', 'pig', 'what');
    }
}
```

##### Strict Mode

[](#strict-mode)

`new RESTfulRouter(true)` to open strict mode.

In this mode, uri will matches **strictly** and new `` style syntax was introduced.

eg. `'/user/'` will match `'/user/micheal'`, but not match `'/user/micheal/age'`, also not match `'/user/micheal/'`.

Type filter supported by ``.

Current filters

- int : pure number

eg. `'/user/'` will match `'/user/123`, but not match `'/user/micheal'`.

Because it base on `YAF\Route\Regex`, some regex can be used. And currently you can't use `'()'`, it will cause error.

eg. `'/blog/?'` will match `'/blog'` or `'/blog/'`.

---

### Class: AdaptiveView

[](#class-adaptiveview)

Render with different way(renderer) according to view file's extension name. Use default `Yaf Simple View` as fallback if no renderer matched.

##### $view = new AdaptiveView($path = '{yaf.application.directory}/views/')

[](#view--new-adaptiveviewpath--yafapplicationdirectoryviews)

- $path **String**: path of view files located, default is '{yaf.application.directory}/views/'

Create a view.

##### $view-&gt;on($extname, $renderder)

[](#view-onextname-renderder)

- $extname **String**: view file's extension name
- $renderer($file, $data) **Function**: called when extname matched, should `return` the rendered result.

Register a renderer with extname.

##### $view-&gt;\*

[](#view-)

Other common methods see [Yaf/View/Interface](http://www.php.net/manual/en/class.yaf-view-interface.php)

#### Example

[](#example-1)

`Bootstrap.php`

```
class Bootstrap extends \Yaf\Bootstrap_Abstract {
    function _initView(\Yaf\Dispatcher $dispatcher) {
        $view = new \Yaf\Extras\AdaptiveView;
        $path = $view->getScriptPath();

        // plain text TEST
        $view->on('txt', function ($file, $data) use ($path) {
            return file_get_contents( $path .$file ) .' THIS IS JUST A TEST';
        });

        // twig
        $view->on('twig', function ($file, $data) use ($path) {
            $loader = new Twig_Loader_Filesystem($path);
            $twig = new Twig_Environment($loader);
            return $twig->loadTemplate($file)->render($data);
        });

        $dispatcher->disableView(); // disable auto-render
        $dispatcher->setView($view);
    }
}
```

Now you can use this view in `YourController.php`

```
class TestController extends \Yaf\Controller_Abstract {
    public function testAction() {
        $view = $this->getView();
        $view->assign('content', 'Hello World');
        $view->display('text.txt');
        // $view->display('text.twig'); // render use twig
    }
}
```

---

### Class: ExtendedController

[](#class-extendedcontroller)

Common controller base on `\Yaf\Controller_Abstract` with many useful methods;

#### flash

[](#flash)

Flash messaging

##### $this-&gt;flash($msg, $type = 'info')

[](#this-flashmsg-type--info)

Store message for next request

##### $this-&gt;flashNow($msg, $type = 'info')

[](#this-flashnowmsg-type--info)

For current request

##### $this-&gt;getFlash()

[](#this-getflash)

Retrieve message for current request

###### example

[](#example-2)

```
class FooController extends ExtendedController {
    public function indexAction() {
        $this->flash('yep', 'success');
        $this->flashNow('nope', 'error');

        foreach ($this->getFlash() as $flash) {
            echo $flash['msg']; // 'nope' in current, 'yep' for next
            echo $flash['type'];
        }
    }
}
```

###  Health Score

29

—

LowBetter than 63% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity52

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

Every ~48 days

Total

6

Last Release

4294d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/608594ff032ac459eb24eb5eb9a0d5ad76e9ebd7c6575eeb613daa1fbd756a0b?d=identicon)[rhyzx](/maintainers/rhyzx)

---

Top Contributors

[![rhyzx](https://avatars.githubusercontent.com/u/1676871?v=4)](https://github.com/rhyzx "rhyzx (31 commits)")

---

Tags

twigextensionsviewrestfulyaf

### Embed Badge

![Health badge](/badges/yaf-extras/health.svg)

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

###  Alternatives

[wyrihaximus/twig-view

Twig powered View for CakePHP

824.7M](/packages/wyrihaximus-twig-view)[craue/twigextensions-bundle

Useful Twig extensions for your Symfony project.

81212.3k](/packages/craue-twigextensions-bundle)[shoot/shoot

Shoot aims to make providing data to your templates more manageable

41229.9k2](/packages/shoot-shoot)[vojtasvoboda/oc-twigextensions-plugin

Register more Twig filters for your OctoberCMS templates

198.1k1](/packages/vojtasvoboda-oc-twigextensions-plugin)[yepsua/smartwig-bundle

The jQuery, jQueryUI (and more) Symfony Bundle

224.0k](/packages/yepsua-smartwig-bundle)

PHPackages © 2026

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