jfsimon/datagrid

该软件包最新版本(dev-master)没有提供许可证信息。

PHP 数据网格组件

dev-master 2013-07-04 16:12 UTC

This package is not auto-updated.

Last update: 2024-09-23 11:10:26 UTC


README

该组件的主要目标是将任何数据源的结果集渲染为具有排序和过滤功能的 HTML 表格(适用于后端)。该组件旨在与框架无关,并提供用于大多数常用 PHP 框架的绑定。

要查看组件的实际应用,您可以查看验收测试

创建 CRUD 操作

$actions = Actions::enable()
    ->addGlobalRoute('create', 'beatle_create')
    ->addEntityRoute('read', 'beatle_read', array('beatle' => 'slug'))
    ->addEntityRoute('update', 'beatle_update', array('beatle' => 'slug'))
    ->addEntityRoute('delete', 'beatle_delete', array('beatle' => 'slug'))
;

1 - 使用自定义数据的使用方法

$beatles = array(
  array('slug' => 'john',    'name' => 'John Lenon',       'birthday' => new \DateTime('1940-10-09'), 'alive' => false),
  array('slug' => 'paul',    'name' => 'Paul McCartney',   'birthday' => new \DateTime('1942-06-18'), 'alive' => true),
  array('slug' => 'georges', 'name' => 'Georges Harrison', 'birthday' => new \DateTime('1943-02-25'), 'alive' => false),
  array('slug' => 'ringo',   'name' => 'Ringo Starr',      'birthday' => new \DateTime('1940-07-07'), 'alive' => true),
);
$schema = Schema::create()
    ->add('name', 'string', array('label' => 'Member name')
    ->add('birthday', 'datetime', array('time_format' => \IntlDateFormatter::NONE))
    ->add('alive', 'boolean', array('label' => 'Still alive?', 'false_value' => 'no more :('))
;
$factory = new Factory();
$grid = $factory->createGrid(new Collection($beatles), array('schema' => $schema, 'actions' => $actions));
echo  $this->getTwig()->render('{{ datagrid(grid) }}', array('grid' => $grid));

2 - 使用 Doctrine 的用法

$factory = new DoctrineFactory($em);
echo $factory
    ->createGrid(new Collection($em->findAll('Beatle')), array('actions' => $actions))
    ->render(new TwigRenderer($twig, 'beatles.html.twig'));

两者都会渲染