Skip to content

Latest commit

 

History

History
50 lines (35 loc) · 1.59 KB

README.md

File metadata and controls

50 lines (35 loc) · 1.59 KB

yii2-recently-viewed-behavior

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