zacksleo/yii2-recently-viewed-behavior
yii2 最近浏览行为
1.0.0
2017-08-27 16:34 UTC
Requires
- yiisoft/yii2: *
Requires (Dev)
- phpunit/phpunit: ^6.3
This package is auto-updated.
Last update: 2024-09-08 07:17:35 UTC
README
快速开始
安装
composer install zacksleo/yii2-recently-viewed-behavior
使用
use yii\web\Controller; use zacksleo\yii2\behaviors\RecentlyViewedBehavior; class DefaultController extends Controller { public function behaviors() { return [ 'recentlyViewed' => [ 'class' => RecentlyViewedBehavior::className(), 'limit' => 5, // Limit the number of recently viewed items stored. 0 = no limit. ], ]; } public function actionView($id) { // set recently models $model = $this->findModel($id); $this->setRecentlyViewed(get_class($model), $id); // get recently models $this->getRecentlyViewed(get_class($model)); }