Download the PHP package rareloop/view-models without Composer
On this page you can find all versions of the php package rareloop/view-models. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rareloop/view-models
More information about rareloop/view-models
Files in rareloop/view-models
Package view-models
Short Description A small package to make dealing with views easier
License MIT
Homepage https://github.com/Rareloop/view-models
Informations about the package view-models
This package is deprecated. View Models are now baked into the Lumberjack core.
View Models
Here, a ViewModel
refers to something that takes data and transforms it into the correct format for a specific view. They are input-output machines.
For example, for this twig
view:
You will need to construct an array that looks like this (e.g. in your controller):
ViewModels abstract away that transformation. This means you don't have to duplicate that transformation logic across multiple controllers, making your code eaiser to change.
Postcardware
You're free to use this package (it's MIT-licensed), but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: 12 Basepoint, Andersons Road, Southampton, Hampshire, SO14 5FE.
Installation
You can install the package via composer:
View Model Usage
They should always return an array. The easiest way to achieve this is to run your data through the compose
method on the View Model.
They should not fetch data from anywhere (e.g. database). This is the job of a ViewModelComposer
.
Using an example ViewModel
(e.g. in a controller):
Here is an example ViewModel
implementation:
Introducing View Model Composers
A ViewModelComposer
is simply a wrapper around a ViewModel
, but is only concerned how to get data ready for a ViewModel
.
These should be used instead of duplicating logic when creating ViewModel
s (e.g. in controllers).
Example ViewModelComposer
implementation:
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.