PHP code example of zacksleo / yii2-recently-viewed-behavior
1. Go to this page and download the library: Download zacksleo/yii2-recently-viewed-behavior library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zacksleo / yii2-recently-viewed-behavior example snippets
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));
}