PHPackages                             aequasi/view-model-bundle - 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. aequasi/view-model-bundle

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

aequasi/view-model-bundle
=========================

Bundle to add ViewModel capabilities to Symfony2

4.0.2(9y ago)105.0kMITPHP

Since Jan 24Pushed 8y ago3 watchersCompare

[ Source](https://github.com/aequasi/view-model-bundle)[ Packagist](https://packagist.org/packages/aequasi/view-model-bundle)[ RSS](/packages/aequasi-view-model-bundle/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (1)Versions (12)Used By (0)

view-model-bundle
=================

[](#view-model-bundle)

Bundle to add View Model capabilities to Symfony2

This bundle is not receiving any more support.
==============================================

[](#this-bundle-is-not-receiving-any-more-support)

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

[](#requirements)

Requires

- [composer](http://www.getcomposer.org/)
- `symfony/symfony >=2.3.0`

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

[](#installation)

In your project root:

```
composer require aequasi/view-model-bundle ~4.0.0
```

In your `app/AppKernel.php`

```
public function registerBundles()
{
    $bundles = array(
        // ...
        new Aequasi\Bundle\ViewModelBundle\AequasiViewModelBundle(),
    );
    // ...
}
```

Usage
-----

[](#usage)

To make a view model, create a new class that implements the [`ViewModelInterface`](https://github.com/aequasi/view-model-bundle/blob/master/src/Aequasi/Bundle/ViewModelBundle/View/Model/ViewModelInterface.php). There are some other classes in that namespace that make it easy to make your own view model. I heavily suggest extending the [`AbstractViewModel`](https://github.com/aequasi/view-model-bundle/blob/master/src/Aequasi/Bundle/ViewModelBundle/View/Model/AbstractViewModel.php). There are also two classes in that namespace that extend the abstract class:

- [`HtmlViewModel`](https://github.com/aequasi/view-model-bundle/blob/master/src/Aequasi/Bundle/ViewModelBundle/View/Model/HtmlViewModel.php) - Sets a content type of `text/html` and doesnt do anything fancy to build the view
- [`JsonViewModel`](https://github.com/aequasi/view-model-bundle/blob/master/src/Aequasi/Bundle/ViewModelBundle/View/Model/JsonViewModel.php) - Sets a content type of `application/json` and doesnt do anything fancy to build the view

Example:

```
