liubinas/upvote-bundle
Composer 安装命令:
composer require liubinas/upvote-bundle
包简介
Upvote and downvote (aka thumbs up) bundle for Symfony project
README 文档
README
LtUpvoteBundle is upvote and downvote (thumbs up and thumbs down) component for Symfony 3.0 project
Features
- Configurable vote permissions
- Automatically limit unauthenticated upvotes/downvotes by IP
- Optionally hide upvote/downvote button
- Pure JavaScript frontend component implementation
- Unit tested
System requirements
- Symfony 3.0
- Doctrine bundle with configured database connection
Installation
- Require LtUpvoteBundle over composer in your existing Symfony project:
composer require liubinas/upvote-bundle
- Initialize it in the app/AppKernel.php file:
$bundles[] = new Lt\UpvoteBundle\LtUpvoteBundle();
- Import LtUpvoteBundle routing:
# app/config/routing.yml lt-upvote: resource: "@LtUpvoteBundle/Resources/config/routing.xml"
- Create required database tables:
$ bin/console doctrine:schema:update
Configuration
The following is an example configuration defining basic context types blog-post and
comment:
# app/config/config.yml lt-upvote-bundle: types: blog-post: # Custom context type show_upvote: true show_downvote: true allow_unauthenticated_upvote: true allow_unauthenticated_downvote: false comment # Custom context type having the default values all true
Test run
Start web server:
$ bin/console server:start
Test page could be accessed by navigating to
http://<dev-host>/lt-upvote-test on your dev environment.
Front-end
Front-end functionality is implemented in a single dependency free JavaScript file. Styles are defined in CSS file which could be used out of the box or adopted according to custom requirements.
JavaScript
- Include JavaScrip module file (Twig syntax):
<script src="{{asset('/bundles/ltupvote/js/lt-upvote.js')}}"></script>
- Initialize JavaScript module in your HTML page:
<script language="JavaScript"><!-- ltupvote.init(); //--> </script>
CSS
- Include basic CSS file in your html
<head>section:
<link rel="stylesheet" type="text/css" href="{{ asset('/bundles/ltupvote/css/lt-upvote.css') }}">
Twig
- Include one or more front end components into your page rendered over Controller
{{ render(
controller(
'lt_upvote_bundle.controller.default:renderVoteComponent',
{
'subjectType': '[TYPE]',
'subjectId': '[ID]',
'css_class': '[CLASS]'
}
)
) }}
Where:
[TYPE]is context type value.[ID]is Subject ID value.[CLASS]is component specific styling CSS class. Predefined styles areStyle1,Style2.
See test.html.twig file for example implementation.
JavaScript Custom Event handling
On each upvote/downvote action JavaScript event is dispatched.
This action could be handled by adding custom event listener for ltu event type.
An example code for unauthenticated downvote handling:
addEventListener('ltu', function(event) { if (event.detail.unauthenticatedError) { alert('This action is permitted for the logged in visitors only.'); } })
The following properties describing performed action could be accessed from even.detail data object: id, type, counter, action, unauthentificated, unauthentificatedError.
License
This bundle is under the MIT license. See the complete license in LICENSE file. f
liubinas/upvote-bundle 适用场景与选型建议
liubinas/upvote-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 05 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 liubinas/upvote-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 liubinas/upvote-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-05-07