lugano/yii2-count-user

统计网站上的浏览量和用户数。

安装: 32

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:yii2-extension

1.0.1 2016-06-13 16:31 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:04:11 UTC


README

#用于YII2的用户统计模块,通过电子邮件发送报告

安装

可以通过以下简单步骤安装扩展

  1. 将 "lugano/yii2-count-user": "*" 添加到 composer.json 文件的 require 部分。
  2. 运行 composer install 安装指定的扩展。
  3. 执行 yii migrate --migrationPath=vendor/lugano/yii2-count-user/migrations

使用方法

假设,您有一个包含4个页面的网站。这些页面通过 SiteController 显示用户。这个 SiteController 扩展了 YII2 的 Controller,并具有 actionIndex、actionAdverbs、actionVerbs、actionDictionary 等方法。

以下代码显示了网站的默认 YII2 控制器。

SiteController extends Controller {

public $hosts;

public $views;

public function actionIndex(){

  self::countUser();
  return $this->render('index');

}

public function actionAdverbs(){

  self::countUser();
  return $this->render('adverbs');

}

public function actionVerbs(){

 self::countUser();
 return $this->render('verbs');

}

public function actionDictionary(){

  self::countUser();
  return $this->render('dictionary');

} }

为了统计您网站的浏览量和用户数,您必须执行以下操作

  1. 在 SiteController 的头部文件中添加 use lugano\userCounter\controllers\DefaultController;

  2. 在您 SiteController(默认控制器)中添加方法;

    public function countUser() { $settings = array( 'posmail' => 'xxxx@ukr.net', 'posname' => 'my-site.com', 'period' => '1...365' ); $temp = new DefaultController($settings); $report = $temp->counter(); $this->views = $report['views']; $this->hosts = $report['hosts'];

    }

  3. 在您的 SiteController 中添加两个公共属性 $host 和 $views;

  4. 在每个方法 actionIndex、actionAdverbs、actionVerbs、actionDictionary 中调用 self::countUser();

  5. 将以下字符串添加到 main.php 文件中:

context->hosts .'   '.'浏览量:'. $this->context->views; ?>

描述 "DefaultController" 类的变量 $setting

'posmail' - 接收网站报告的电子邮件;'posname' - 发件人名称(您的网站);'period' - 从您网站发送报告的周期(不少于1天,不多于365天);