JBuilderBundle
Symfony2/Symfony3 Bundle for JBuilder, (*1)
Installation
Add this lines to your composer.json:, (*2)
{
"require": {
"jbuilder/jbuilder-bundle": "~1.0"
}
}
And then execute:, (*3)
$ php composer.phar install
And import a JBuilderBundle to AppKernel.php:, (*4)
$bundles = array(
new JBuilder\JBuilderBundle\JBuilderJBuilderBundle(),
);
Usage
Insert the following code to controller:, (*5)
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:, (*6)
$json->buildArray($posts, function($json, $post) {
$json->id = $post->getId();
$json->title = $post->getTitle();
});
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request
Copyright
Copyright (C) 2016 Dai Akatsuka, released under the MIT License., (*7)