lch/components-bundle
Composer 安装命令:
composer require lch/components-bundle
包简介
Common components to all LCH bundles
README 文档
README
This Symfony bundle provides all necessary bricks needed accross other LCH bundles.
Installation
composer require lch/components-bundle "^1.2.7"
Traits
UUID
Using the Uuidable will add to your entity a Ramsey UUID identity field.
Note: This does not handle the configuration steps for you.
Repository traits
In order to gather some behavior une one places, we introduce following repository traits.
PaginableEntityRepository
This provides one public method to retrieve a Doctrine Paginator object. Below is the signature
/** * @param QueryBuilder $qb the QueryBuilder object containing the query description * @param int $page the page wanted (set to 1 by default) * @param int|null $maxResults the batch size, if any * * @return Paginator */ public function getPaginator(QueryBuilder $qb, int $page = 1, int $maxResults = null)
Everything is straightforward here.
CountableEntityRepository
This provides a simple method to easily get total query items count.
SearchableEntityRepository
Full text search method
This is useful for example in AJAX actions (in a not-API context) where you need to retrieve a list of entity in large term context : classical AJAX search.
/** * Used to search in like mode in entity fields * @param array $fields the fields names wanted to be searched in * @param string $term the term to be searched * @param int|null $maxResults the batch size, if any. * @param string|null $language if any, ISO code language to filter items on * * @return array */ public function findByFulltextTerm( array $fields, string $term, int $maxResults = null, string $language = null ): array
Twig
Macros
Simple admin pagination
If using PaginableEntityRepository above, you can then pass pagination object
public function list(int $page): Response { // get items before with a repository method returning paginator return $this->render('admin/menu/list.html.twig', [ 'menus' => $menus, 'pagination' => [ 'page' => $page, 'nbPages' => ceil($menus->count() / $nbItemsPerPage) ] ]); }
Then in twig you can generate simple pagination component:
{% import "@LchComponents/macros/lch-components-utils.html.twig" as lch_utils %}
...
{{ lch_utils.admin_paginate(pagination.page, pagination.nbPages) }}
统计信息
- 总下载量: 719
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-05-24