smile / simple-page-view-bundle
在您的网站上轻松添加轻量级和简单的页面浏览计数系统
v1.0
2015-02-26 20:39 UTC
This package is not auto-updated.
Last update: 2024-09-14 16:07:54 UTC
README
SimplePageViewBundle 是在您的网站上轻松添加轻量级和简单页面浏览计数系统的一种方法。
它不提供会话管理。所有显示的页面(刷新、F5等)都会被处理。
#安装
步骤 1: 使用 composer 下载 Bundle
composer require "smile/simple-page-view-bundle:~0.1"
步骤 2: 启用 Bundle
在内核中启用 Bundle
//app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Smile\Bundle\SimplePageViewBundle\SmileSimplePageViewBundle(), ); }
步骤 3: 启用路由
在 app/config/routing.yml 中加载 Bundle 路由
smile_simple_page_view:
resource: "@SmileSimplePageViewBundle/Controller/"
type: annotation
prefix: /
步骤 4: 更新数据库模式
运行更新数据库模式命令
php app/console doctrine:schema:update --force
使用
Twig 函数
使用以下 Twig 函数启用页面中信息的收集
{{ smile_page_view(pageType, pageId) }}
pageType 用于说明您当前所在的页面类型(例如,如果您的应用程序是新闻文章,可以将类型设置为 'news')。
pageId 是当前页面元素的唯一标识符(例如,文章的数字 ID)。这不是必需的。
批量
为了聚合和压缩页面浏览数据,您必须运行批量命令 php app/console smile:pageviews:aggregate
。
您可以将它添加到 cron 任务中(我们建议每天运行一次)
此批量通过类型、ID 和日期压缩 smile_page_view_stats
表中的数据,并从 smile_page_view_storage
表中删除已处理的条目。