承接 samson/dataview-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

samson/dataview-bundle

Composer 安装命令:

composer require samson/dataview-bundle

包简介

Make configuring different serialization views for your entities easy and maintainable.

README 文档

README

Example of use

// class
class SampleDataView extends AbstractType
{
    public function getName()
    {
        return 'sample';
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name_of_key', 'type_of_key', array('property_path' => 'optionalPath', /** other options */))
            ->add('children', 'collection', array('type' => new ChildDataView())
        ;

        $builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $e) {
            $e->getForm()->add('new_key', 'type_of_key', array('mapped' => false, 'data' => $e->getData()->getSomeCustomData());
        }

        // or you can use this convenience method:
        $builder->addFixed('new_key', 'type_of_key', function($data) { return $data->getSomeCustomData(); });
    }
}

// use
$view = $container->get('samson.dataview.factory')->create(new SampleDataView(), $sample);
$data = $view->createView()->getData();

// $data is now something like:
// array( 'name_of_key' => 'value_of_$entity->getOptionalPath()', 'children' => array(array(), array(), array(), 'etc' ), 'new_key' => 'value_of_$entity->getSomeCustomData()' );

If your object is a doctrine entity, you can let the guessers so the work for you:

class SampleDataView extends AbstractType
{
    public function getName()
    {
        return 'sample';
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name_of_key')
            ->add('children')
        ;
    }
}

By default, if a one-to-many or many-to-many collection is encountered, the type "collection" will be setup with the option type set to entity. The entity type by default will try to convert your entity to an array with keys id and name, the latter being the object cast to string.

Introduction

The DataViewBundle is based in great upon the Form component in symfony. It makes use of the FormView part to convert an object scheme into a basic array, making full use of the flexibility the Form component offers.

A problem often encountered, for example, is having a situation where you want to serialize a "Project" entity with all it's "Product" children in one controller, and a "Product" entity with it's "Product" parent in the other. In order to prevent an endless serialization loop, either make use of the options to tell each type what to include and what not, or simply add the relevant fields to the View from the controller.

统计信息

  • 总下载量: 867
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 1

GitHub 信息

  • Stars: 8
  • Watchers: 13
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-07-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固