zacksleo / yii2-recently-viewed-behavior
yii2 recently viewed behavior
Installs: 391
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: *
Requires (Dev)
- phpunit/phpunit: ^6.3
This package is auto-updated.
Last update: 2024-11-08 07:41:18 UTC
README
Quick Start
Install
composer install zacksleo/yii2-recently-viewed-behavior
Usage
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)); }