enterprisephp / display-bundle
此Bundle提供为给定对象生成视图的功能
Requires
- php: ^5.5.9|~7.0
- psr/log: ^1.0
- symfony/framework-bundle: ^2.7|^3.0
Requires (Dev)
- jms/serializer-bundle: ^1.0
- sensio/framework-extra-bundle: ^3.0
- symfony/browser-kit: ^2.7|^3.0
- symfony/dependency-injection: ^2.7|^3.0
- symfony/form: ^2.7|^3.0
- symfony/phpunit-bridge: ~2.7|^3.0
- symfony/security-bundle: ^2.7|^3.0
- symfony/serializer: ^2.7|^3.0
- symfony/twig-bundle: ^2.7|^3.0
- symfony/validator: ^2.7|^3.0
- symfony/web-profiler-bundle: ^2.7|^3.0
- symfony/yaml: ^2.7|^3.0
Suggests
- jms/serializer-bundle: Add support for advanced serialization capabilities, recommended, requires ^1.0
- sensio/framework-extra-bundle: Add support for route annotations and the view response listener, requires ^3.0
- symfony/expression-language: Add support for using the expression language in the routing, requires ^2.7|^3.0
- symfony/serializer: Add support for basic serialization capabilities and xml decoding, requires ^2.7|^3.0
- symfony/validator: Add support for validation capabilities in the ParamFetcher, requires ^2.7|^3.0
This package is not auto-updated.
Last update: 2024-09-24 18:48:52 UTC
README
轻松为给定实体/对象生成视图
非常基本的截图;
相关链接;###
- academic/vipa#990
- https://github.com/ojs/ojs/blob/master/src/Ojs/CoreBundle/Service/Twig/DisplayExtension.php
- 开发步骤可以从以下链接查看:https://github.com/behramcelen/symfony-bundle-develop
- 基本测试和逻辑控制器及视图可以在以下链接找到:https://github.com/behramcelen/symfony-bundle-develop/blob/master/src/AppBundle/Controller/DisplayController.php#L16
- https://github.com/behramcelen/symfony-bundle-develop/blob/master/src/AppBundle/Resources/views/Display/display.html.twig#L7
安装
步骤1:下载Bundle
打开命令行,转到您的项目目录,并执行以下命令以下载此bundle的最新版本
$ composer require enterprisephp/display-bundle "dev-master"
此命令需要您全局安装Composer,如Composer文档中的安装章节所述。
步骤2:启用Bundle
然后,通过将其添加到项目中的app/AppKernel.php
文件中注册的bundle列表来启用bundle
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new EP\DisplayBundle\EPDisplayBundle(), ); // ... } // ... }
DisplayTrait
在您想要显示对象/实体的地方使用DisplayTrait(非常重要)
namespace AppBundle\Entity; use EP\DisplayBundle\Entity\DisplayTrait; class MyEntity { use DisplayTrait; }
配置
将以下配置添加到config.yml
文件中
ep_display:
global:
image_render: true # (optinal) defaults to true
file_render: true # (optinal) defaults to true
template: EPDisplayBundle::display.html.twig # (optinal) defaults to EPDisplayBundle:display.html.twig template
exclude_vars: # (optinal) defaults to empty array
- excludeField
- hiddenField
- password
array_collection_render: true # (optinal) defaults to true
collection_item_count: 5 # (optinal) defaults to 10
用法
如果您不想做任何极端的事情,仅显示在模板中;
{{ display(entity) }} # so easy isn't it 😉
您可以通过类注解覆盖所有bundle配置
相关: https://github.com/EnterprisePHP/EPDisplayBundle/blob/master/Annotation/Display.php#L11
namespace AppBundle\Entity; use EP\DisplayBundle\Annotation as Display; /** * @Display\Display( * image_render=false, # optinal * file_render=false, # optinal * template="my_entity_special_template.html.twig", # optinal * array_collection_render=true, # optinal * collection_item_count=8, # optinal * ) */ class MyEntity {
如果您想排除实体的特定字段,请使用Exclude注解
相关: https://github.com/EnterprisePHP/EPDisplayBundle/blob/master/Annotation/Exclude.php
namespace AppBundle\Entity; use EP\DisplayBundle\Annotation as Display; class DummyEntity { /** * @Display\Exclude */ protected $unPublicfieldForOnlyThisEntity;
公开字段。所有字段默认公开,但如果您在配置中排除,但只想公开此字段一次;
namespace AppBundle\Entity; use EP\DisplayBundle\Annotation as Display; class DummyEntity { /** * @Display\Expose */ protected $oneTimeExposeField;
带有链接的文件公开;
namespace AppBundle\Entity; use EP\DisplayBundle\Annotation as Display; class DummyEntity { /** * @Display\File(path="uploads/files") */ protected $mainFile;
带有img标签的图像公开;
namespace AppBundle\Entity; use EP\DisplayBundle\Annotation as Display; class DummyEntity { /** * @Display\Image( * path="uploads/files", * height="50", * width="70", * ) */ protected $cover;
您可以在display函数的第二个参数上指定所有配置,从模板中;
{{ display(entity, { files: { my_file: { path: "web/uploads" } }, images: { header: { path: "web/images", width: "70", height: "50" } }, exclude: "myVeryPrivateField", // can be array expose: "onlyForThisPageExposeVar", // can be array image_render: true, file_render: true, array_collection_render: false, collection_item_count: 90, template: "my_stylish_template.html.twig" }) }}
报告问题或功能请求
问题和功能请求在Github问题跟踪器中跟踪。
当报告一个错误时,最好在基本项目中重现它,该项目使用Symfony标准版构建,以便bundle的开发者可以通过简单地克隆它并遵循一些步骤来重现问题。