axgle / yii2-hitable-behavior
v0.0.6
2016-10-08 01:29 UTC
This package is not auto-updated.
Last update: 2024-09-28 19:47:30 UTC
README
版本
v0.0.6
安装
composer require --no-plugins -vvv axgle/yii2-hitable-behavior
主要迁移
yii migrate --migrationPath=@axgle/yii2/behavior/migrations
配置
<?php class Post extends \yii\db\ActiveRecord { public function behaviors() { return [ 'hit' => [ 'class' => \axgle\yii2\behavior\HitableBehavior::className(), 'attribute' => 'hits_count', //attribute which should contain uniquie hits value 'group' => false, //group name of the model (class name by default) 'delay' => 60 * 60, //register the same visitor every hour 'table_name' => '{{%hits}}' //table with hits data ] ]; } }
基本用法
$post = Post::findOne(1); //increase counter $post->getBehavior('hit')->touch(); //get hits count echo $post->getBehavior('hit')->getHitsCount();