Count views and users on site.
Installation, (*1)
Extension may be installed by taking the following simple steps:, (*2)
Usage, (*3)
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., (*4)
Code below shows default YII2 controller for site., (*5)
SiteController extends Controller {, (*6)
public $hosts;, (*7)
public $views;, (*8)
public function actionIndex(){, (*9)
self::countUser(); return $this->render('index');
}, (*10)
public function actionAdverbs(){, (*11)
self::countUser(); return $this->render('adverbs');
}, (*12)
public function actionVerbs(){, (*13)
self::countUser(); return $this->render('verbs');
}, (*14)
public function actionDictionary(){, (*15)
self::countUser(); return $this->render('dictionary');
} }, (*16)
In order to count users and views your site you must do several action:, (*17)
1) Add use lugano\userCounter\controllers\DefaultController; in header file with your SiteController;, (*18)
2) Add method in you SiteController(your default controller);, (*19)
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) Add two public properties $host and $views to your SiteController;, (*20)
4) Call self::countUser() in each your method actionIndex, actionAdverbs, actionVerbs, actionDictionary, (*21)
5) Add to your main.php file string like context->hosts .' '.'Views: '. $this->context->views; ?>, (*22)
Describing for variable $setting of class "DefaultController", (*23)
'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);, (*24)