appventus/avlist-bundle
最新稳定版本:1.0.1
Composer 安装命令:
composer require appventus/avlist-bundle
包简介
Symfony AvListBundle
关键字:
README 文档
README
Easily make paginate and orderable list in Symfony2
- Install
Add this in your composer :
"appventus/avlist-bundle": "dev-master"
- How to use it ?
a) Controller
This is a classic action to list an entity :
use Symfony\Component\HttpFoundation\Request;
class FooController extends Controller
{
/**
* Lists all Foo entities.
*
*/
public function indexAction(Request $request)
{
$em = $this->getDoctrine()->getEntityManager();
$qb = $em->getRepository(MyBundle:Foo)->findAll();
// Create an AvList
$list = $this->get('av_list')->getList($qb, null, array(
'max_per_page' => 20,
));
$list->addColumn('title', null, 'myList.column.title', true, 'entity.title');
$list->addColumn('startDate', array(array("name" => "date", "params" => array('d/m/Y'))), 'myList.column.startDate', true, 'entity.startDate');
return array(
'list' => $list,
);
if ($this->get('request')->isXmlHttpRequest()) {
return $this->render($list->getTemplate(), array(
'list' => $list,
));
} else {
return array(
'list' => $list,
);
}
}
}
The addColunmn allow you to add/define the columns to display in the list. In order :
-
- You can define the field to display
-
- Is there some special Twig filters to use on the variable to display correctly ?
-
- The label (th)
-
- Do we may sort on this column ?
-
- If so, on which field
b) View (optional):
If you want to override default views, you'll have to write an index with the layout, and a partial witch just contain the list:
index.html.twig :
{% extends "MyBundle::layout.html.twig" %}
{% block content %}
<h1>Foo list</h1>
{% include 'MyBundle:Foo:indexPartial.html.twig' with {'list':list}%}
{% endblock %}
Yeah, it's pretty minimalist, but it's very important.
And now our Partial :
{% if list.pager.nbResults > 0 %}
<div id="{{ list.option('id') }}">
<table class="table">
<thead>
<tr>
<th class="sortable" data-target="f.name">Name</th>
<th class="sortable" data-target="f.price">Price</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{% for foo in list.pager %}
<tr>
<td>{{ foo.name }}</td>
<td>{{ foo.price }}</td>
<td>{{ foo.name }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% include 'AvListBundle:AvList:control.html.twig' with {'list':list}%}
</div>
{% else %}
<p>No Foos :(</p>
{% endif %}
And voila !
- How it works ?
In the partial view, you set on the th tag a class sortable and an id with the value of the field you want to search on. In our exemple, the entity Foo has the alias "f" in the query builder, so to sort by Foo's name, you set the following th id: "f.name".
- Options
This bundle use the PagerFanta bundle to build paginator, more specificly the TwitterBootstrapView. Options are available for this view, and you can pass them as second argument when you instanciate AvList:
$list = $this->get('av_list');
$list->addOption("proximity", 3);
$list->addOption("previous_message", "Précédent");
Please refer to PagerFanta doc for more information
- Multiple list in a page
If you need to have several lists components in a single page, you will have to define the route option (to specify a different url to call that the request one). Optionnally and if your route requires params, you obviously may pass an array through the route_parameters option. Also, you won't be able to use the av_list service because of a singleton pattern issue (if you use the service, you always will use the same object and so on, you will overwrite the values instead of create a new list.
/**
* Lists all Help\FaqItem entities.
*
* @Route("/", name="admin_myentity_list")
* @Route("/ajax/cat/{id}", name="ajax_admin_myentity_list_by_category")
* @Method("GET")
* @Template()
*/
public function indexAction($id = null)
{
$categories = Your_function();
foreach ($categories as $key => $category) {
$list = new AvList($request, $this->get('templating'));
$list->setQueryBuilder($em->getRepository('MyBundle:MyEntity')->createQueryBuilder('e')->where('e.category = :category')->setParameter('category', $category));
$list->setTemplate($partialTemplate);
$list->setOptions(array(
'route' => 'ajax_admin_myentity_list_by_category',
'route_parameters' => array('id' => $category->getId()),
'theme' => 'range',
'maxPerPage' => 5,
'container_class' => $category->getId().'-myentity-list',
'container_id' => $category->getId().'-myentity-list'
));
$params["lists"][$category->getId()] = $list;
}
}
- Custom control theme
By default, AvList provides one theme : range. This theme adds the basics actions to get something like this : <- [10,20] on 100 ->
If you want to, you can create your own theme by setting your theme name as "theme" option and to put it in the app/Resources/AvListBundle/views/AvList/yourCustomThemeFileName.html.twig
appventus/avlist-bundle 适用场景与选型建议
appventus/avlist-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.64k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2013 年 02 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bootstrap」 「paginator」 「order」 「list」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 appventus/avlist-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 appventus/avlist-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 appventus/avlist-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony DataGridBundle
Sylius plugin that adds the possibility to add products to the shopping cart using a button on the product card.
An ID Generator for PHP based on Snowflake Algorithm (Twitter announced).
Views for the package MedicOneSystems Livewire Datatables with Bootstrap 4
MongoDB Adapter to be used with Laminas Paginator
bootstrap select field module implementing http://silviomoreto.github.io/bootstrap-select/
统计信息
- 总下载量: 9.64k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-02-17