Download the PHP package czepter/cakephp-fractal-transformer-view without Composer
On this page you can find all versions of the php package czepter/cakephp-fractal-transformer-view. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package cakephp-fractal-transformer-view
FractalTransformerView plugin for CakePHP
This plugin is a thin wrapper for JsonView
that allows using Fractal transformers for your API output. What is Fractal?
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
- CakePHP 4.0+ (use ~1.0 for CakePHP 3.1+)
Installation
You can install this plugin into your CakePHP application using Composer.
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 - specify which view vars you want to get serialized by setting serialize
view builder option. E.g.:
The view will look for transformer class starting with entity name. E.g.:
If transformer class not found the variable is serialized the normal way.
Custom transformer class name can be set by defining transformer
view builder option:
You can also define if you don't want to use transformer for certain variables:
You can set a custom serializer (class name or object) via serializer
view builder option:
Bugs & Feedback
https://github.com/andrej-griniuk/cakephp-fractal-transformer-view/issues
Credits
Inspired by @josegonzalez Using Fractal to transform entities for custom api endpoints.
License
Copyright (c) 2016, Andrej Griniuk and licensed under The MIT License.