PHPackages                             jeffersonsimaogoncalves/cakephp-fractal-transformer-view - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. jeffersonsimaogoncalves/cakephp-fractal-transformer-view

ActiveCakephp-plugin[HTTP &amp; Networking](/categories/http)

jeffersonsimaogoncalves/cakephp-fractal-transformer-view
========================================================

CakePHP view builder utilizing Fractal library for entities transformation

v1.3.0(8mo ago)221MITPHPPHP &gt;=7.1CI failing

Since Oct 20Pushed 8mo agoCompare

[ Source](https://github.com/jeffersongoncalves/cakephp-fractal-transformer-view)[ Packagist](https://packagist.org/packages/jeffersonsimaogoncalves/cakephp-fractal-transformer-view)[ Docs](http://github.com/jeffersonsimaogoncalves/cakephp-fractal-transformer-view)[ RSS](/packages/jeffersonsimaogoncalves-cakephp-fractal-transformer-view/feed)WikiDiscussions master Synced today

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

FractalTransformerView plugin for CakePHP
=========================================

[](#fractaltransformerview-plugin-for-cakephp)

This plugin is a thin wrapper for `JsonView` that allows using [Fractal transformers](http://fractal.thephpleague.com/transformers/) for your API output. What is [Fractal](http://fractal.thephpleague.com/)?

> Fractal provides a presentation and transformation layer for complex data output, the like found in RESTful APIs, and works really well with JSON. Think of this as a view layer for your JSON/YAML/etc. When building an API it is common for people to just grab stuff from the database and pass it to json\_encode(). This might be passable for “trivial” APIs but if they are in use by the public, or used by mobile applications then this will quickly lead to inconsistent output.

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

[](#requirements)

- CakePHP 3.6+

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

[](#installation)

You can install this plugin into your CakePHP application using [Composer](http://getcomposer.org).

```
composer require jeffersonsimaogoncalves/cakephp-fractal-transformer-view
```

Usage
-----

[](#usage)

To enable the plugin set `FractalTransformerView.FractalTransformer` class name for viewBuilder. Then you just do what you would normally do in your [data views](http://book.cakephp.org/3.0/en/views/json-and-xml-views.html) - specify which view vars you want to get serialized by setting `_serialize` var. E.g.:

```
namespace App\Controller;

class ArticlesController extends AppController
{
    public function initialize()
    {
        parent::initialize();
        $this->loadComponent('RequestHandler');

        $this->viewBuilder()->className('FractalTransformerView.FractalTransformer');
    }

    public function index()
    {
        // Set the view vars that have to be serialized.
        $this->set('articles', $this->paginate());
        // Specify which view vars JsonView should serialize.
        $this->set('_serialize', ['articles']);
    }
}
```

The view will look for transformer class starting with entity name. E.g.:

```
namespace App\Model\Transformer;

use App\Model\Entity\Article;
use League\Fractal\TransformerAbstract;

class ArticleTransformer extends TransformerAbstract
{
    /**
     * Creates a response item for each instance
     *
     * @param Article $article post entity
     * @return array transformed post
     */
    public function transform(Article $article)
    {
        return [
            'title' => $article->get('title')
        ];
    }
}
```

If transformer class not found the variable is serialized the normal way.

Custom transformer class name can be set by defining `_transformer` view var:

```
$this->set('_transform', ['articles' => '\App\Model\Transformer\CustomArticleTransformer']);
```

You can also define if you don't want to use transformer for certain variables:

```
$this->set('_transform', ['articles' => false]);
```

Bugs &amp; Feedback
-------------------

[](#bugs--feedback)

Credits
-------

[](#credits)

This work is based on the [code by Andrej Griniuk](https://github.com/andrej-griniuk/cakephp-fractal-transformer-view).

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance59

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

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

257d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/411493?v=4)[Jefferson Gonçalves](/maintainers/jeffersongoncalves)[@jeffersongoncalves](https://github.com/jeffersongoncalves)

---

Top Contributors

[![andrej-griniuk](https://avatars.githubusercontent.com/u/2722793?v=4)](https://github.com/andrej-griniuk "andrej-griniuk (14 commits)")[![jeffersongoncalves](https://avatars.githubusercontent.com/u/411493?v=4)](https://github.com/jeffersongoncalves "jeffersongoncalves (10 commits)")[![dakota](https://avatars.githubusercontent.com/u/83255?v=4)](https://github.com/dakota "dakota (1 commits)")

---

Tags

jsonapirestcakephpfractal

### Embed Badge

![Health badge](/badges/jeffersonsimaogoncalves-cakephp-fractal-transformer-view/health.svg)

```
[![Health](https://phpackages.com/badges/jeffersonsimaogoncalves-cakephp-fractal-transformer-view/health.svg)](https://phpackages.com/packages/jeffersonsimaogoncalves-cakephp-fractal-transformer-view)
```

###  Alternatives

[andrej-griniuk/cakephp-fractal-transformer-view

CakePHP view builder utilizing Fractal library for entities transformation

1891.9k](/packages/andrej-griniuk-cakephp-fractal-transformer-view)[mixerapi/mixerapi

Streamline development of API-first applications in CakePHP

4443.7k](/packages/mixerapi-mixerapi)[cakedc/cakephp-api

Api plugin for CakePHP

61114.0k](/packages/cakedc-cakephp-api)[sprintcube/cakephp-rest

Rest API plugin for CakePHP 3

256.8k](/packages/sprintcube-cakephp-rest)

PHPackages © 2026

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