zacksleo/yii2-recently-viewed-behavior

yii2 recently viewed behavior

1.0.0 2017-08-27 16:34 UTC

This package is auto-updated.

Last update: 2024-11-08 07:41:18 UTC


README

StyleCI Build Status Code Climate Scrutinizer Code Quality Code Coverage

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));
    }