Skip to content

Commit

Permalink
Add countViews param to frontend module
Browse files Browse the repository at this point in the history
  • Loading branch information
GutsVadim committed Apr 15, 2020
1 parent 03560ea commit 781111c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 13 additions & 0 deletions frontend/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,18 @@

class Module extends \yii\base\Module
{
const COUNT_VIEWS_PARAM = 'countViews';

public $controllerNamespace = 'bl\articles\frontend\controllers';

protected $defaultParams = [
self::COUNT_VIEWS_PARAM => true
];

public function init()
{
parent::init();

$this->params = array_merge($this->defaultParams, $this->params);
}
}
7 changes: 5 additions & 2 deletions frontend/controllers/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace bl\articles\frontend\controllers;

use bl\articles\common\entities\Article;
use bl\articles\frontend\Module as FrontendModule;
use yii\helpers\Url;
use yii\web\Controller;

Expand Down Expand Up @@ -77,10 +78,12 @@ public function actionIndex($id = null) {
}
}

$article->updateViewCounter();
if ($this->module->params[FrontendModule::COUNT_VIEWS_PARAM]) {
$article->updateViewCounter();
}

return $this->render($articleView, [
'article' => $article
]);
}
}
}

0 comments on commit 781111c

Please sign in to comment.