lugano / yii2-count-user
Count views and users on site.
Installs: 35
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
This package is not auto-updated.
Last update: 2025-02-01 21:30:45 UTC
README
#Module of count of users for YII2 with report by email
Installation
Extension may be installed by taking the following simple steps:
- add "lugano/yii2-count-user": "*" to the require section of your composer.json file.
- run composer install to install the specified extensions.
- execute yii migrate --migrationPath=vendor/lugano/yii2-count-user/migrations
Usage
Suppose, You have site with 4 pages. These pages has been displaying user using SiteController. This SiteController extends Controller from YII2, and has methods , called actionIndex, actionAdverbs, actionVerbs, actionDictionary.
Code below shows default YII2 controller for site.
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');
} }
In order to count users and views your site you must do several action:
-
Add use lugano\userCounter\controllers\DefaultController; in header file with your SiteController;
-
Add method in you SiteController(your default controller);
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'];
}
-
Add two public properties $host and $views to your SiteController;
-
Call self::countUser() in each your method actionIndex, actionAdverbs, actionVerbs, actionDictionary
-
Add to your main.php file string like
Describing for variable $setting of class "DefaultController"
'posmail' - email will be receiving report from site; 'posname' - name for sender(your site); 'period' - period between reports from you site(not less than 1 and not more than 365 days);