diff --git a/frontend/Module.php b/frontend/Module.php index c8ebe1d..973e534 100755 --- a/frontend/Module.php +++ b/frontend/Module.php @@ -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); + } } diff --git a/frontend/controllers/ArticleController.php b/frontend/controllers/ArticleController.php index a20fe51..8ce0cf8 100755 --- a/frontend/controllers/ArticleController.php +++ b/frontend/controllers/ArticleController.php @@ -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; @@ -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 ]); } -} \ No newline at end of file +}