jbuilder/jbuilder-bundle

Symfony2 bundle for JBuilder

Installs: 8 283

Dependents: 0

Stars: 3

Watchers: 2

Forks: 2

Language: PHP

1.0.0 2013-05-21 13:41 UTC

README

Symfony2 Bundle for JBuilder

Installation

Add this lines to your composer.json:

{
    "require": {
        "jbuilder/jbuilder-bundle": "1.0.*"
    }
}

And then execute:

$ php composer.phar install

And import a JBuilderBundle to AppKernel.php:

$bundles = array(
    new JBuilder\JBuilderBundle\JBuilderJBuilderBundle(),
);

Usage

Insert the following code to controller:

public function indexAction()
{
    $posts = $this->getDoctrine()->getRepository('Acme\BlogBundle\Entity\Post')->findAll();

    return $this->get('jbuilder')->render('AcmeBlogBundle:Post:index.json.php', array('posts' => $posts));
}

src/Acme/BlogBundle/Resources/views/Post/index.json.php:

$json->buildArray($posts, function($json, $post) {
    $json->id    = $post->getId();
    $json->title = $post->getTitle();
});

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Copyright

Copyright (C) 2013 Dai Akatsuka, released under the MIT License.