acseo / fast-show-generator-bundle
该包最新版本(v2.0.1)没有提供许可证信息。
一个基于注解或yaml快速生成显示操作的包
v2.0.1
2023-07-03 16:20 UTC
Requires
- doctrine/annotations: ^2.0
- symfony/config: ^5.0
- symfony/dependency-injection: ^5.0
- symfony/http-kernel: ^5.0
- symfony/yaml: ^5.0
This package is not auto-updated.
Last update: 2024-09-13 05:54:17 UTC
README
ACSEOFastShowGeneratorBundle 允许您根据注解或yaml快速生成显示操作。此包由Nicolas Kern(ACSEO)发起。
版本: 2.0 兼容性: Symfony ^5.0, Twig >= 1.5.0
使用Composer安装
$ composer install acseo/fast-show-generator-bundle
Composer会将该包安装到您的项目目录下的vendor/ACSEO
。
如何使用
注解
在实体中
use ACSEO\FastShowGeneratorBundle\Annotations as ACSEOFastShowGeneratorBundle;
对于每个属性
* @ACSEOFastShowGenerator\Show(label="My Property 1", show=true, groups={"default"})
在控制器中
$fastShow = $this->get('acseo_fast_show_generator.driver.annotation'); $fastShow->setEntity(new MyEntity()); $fastShow->setGroup('default'); $fastShow->setClassMetadata($em->getClassMetadata("ACSEOMyBundle:MyEntity")); $fastShowData = $fastShow->getShowableData();
YAML
为每个实体创建一个文件到您的包中
#ACSEO/Bundle/MyBundle/Resources/config/fastshowgenerator/MyEntity.default.fastshowgenerator.yml ACSEO\Bundle\MyBundle\Entity\MyEntity: Columns: myProperty: label: My Property 1 show: true groups: {"default"} myProperty2: label: My Property 2 show: true groups: {"default"}
在控制器中
$fastShow = $this->get('acseo_fast_show_generator.driver.yaml'); $fastShow->setEntity($entity); $fastShow->setGroup('default'); $fastShow->setClassMetadata($em->getClassMetadata($this->getEntityName())); $fastShowData = $fastShow->getShowableData();
可用选项
label : string - optional - if not set, uses the property name capitalized
show : boolean - optional - if not set, value is assumed to be true
groups : array - optional - if not set, group name is "default"
模板
现在,在您的twig文件中,可能是这样的
<table class="table table-striped"> <tbody> {% for propertyName, propertyValue in data %} <tr><td>{{ propertyName }}</td><td>{{ propertyValue }}</td></tr> {% endfor %} </tbody> </table>