jbuilder/jbuilder-bundle

JBuilder 的 Symfony2 扩展包

1.1.1 2016-01-14 06:45 UTC

This package is not auto-updated.

Last update: 2024-09-23 14:54:48 UTC


README

Symfony2/Symfony3 Bundle for JBuilder

安装

将以下行添加到您的 composer.json 文件中

{
    "require": {
        "jbuilder/jbuilder-bundle": "~1.0"
    }
}

然后执行

$ php composer.phar install

然后在 AppKernel.php 中导入 JBuilderBundle

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

使用方法

将以下代码插入控制器

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();
});

贡献

  1. 进行分支
  2. 创建您的功能分支(git checkout -b my-new-feature
  3. 提交您的更改(git commit -am 'Add some feature'
  4. 推送到分支(git push origin my-new-feature
  5. 创建新的拉取请求

版权

版权 (C) 2016 Dai Akatsuka,根据 MIT 许可证发布。