public function init()
 {
     $this->name = \skeeks\cms\comments2\Module::t('app', 'Managing comments');
     $this->modelShowAttribute = "id";
     $this->modelClassName = Comments2Message::className();
     parent::init();
 }
 public function initDataProvider()
 {
     $this->search = new Search(Comments2Message::className());
     $this->dataProvider = $this->search->getDataProvider();
     if ($this->enabledPaging == Cms::BOOL_Y) {
         $this->dataProvider->getPagination()->defaultPageSize = $this->pageSize;
         $this->dataProvider->getPagination()->pageParam = $this->pageParamName;
     } else {
         $this->dataProvider->pagination = false;
     }
     if ($this->orderBy) {
         $this->dataProvider->getSort()->defaultOrder = [$this->orderBy => (int) $this->order];
     }
     return $this;
 }
 public function actionSubmit()
 {
     $rr = new RequestResponse();
     $model = new Comments2Message();
     if ($rr->isRequestOnValidateAjaxForm()) {
         return $rr->ajaxValidateForm($model);
     }
     if ($rr->isRequestAjaxPost()) {
         $model->scenario = Comments2Message::SCENARIO_SITE_INSERT;
         $model->page_url = \Yii::$app->request->referrer;
         if ($model->load(\Yii::$app->request->post())) {
             //Проверка на максимальное количество комментариев к одному посту от одного пользователя.
             $messagesFind = Comments2Message::find();
             if (\Yii::$app->user->isGuest) {
                 $messagesFind->andWhere(['ip' => Request::getRealUserIp()]);
             } else {
                 $messagesFind->andWhere(['created_by' => \Yii::$app->user->identity->id]);
             }
             $messagesFind2 = clone $messagesFind;
             $messagesFind->andWhere(['status' => Comments2Message::STATUS_ALLOWED])->andWhere(['element_id' => $model->element_id]);
             if (\Yii::$app->comments2->maxCountMessagesForUser != 0) {
                 if ($messagesFind->count() >= \Yii::$app->comments2->maxCountMessagesForUser) {
                     $rr->success = false;
                     $rr->message = \skeeks\cms\comments2\Module::t('app', 'You have already added a comment on this post before.');
                     return $rr;
                 }
             }
             //Проверка частоты добавления комментариев
             if (\Yii::$app->comments2->securityEnabledRateLimit == Cms::BOOL_Y) {
                 $messagesFind2 = Comments2Message::find();
                 if (\Yii::$app->user->isGuest) {
                     $messagesFind2->andWhere(['ip' => Request::getRealUserIp()]);
                 } else {
                     $messagesFind2->andWhere(['created_by' => \Yii::$app->user->identity->id]);
                 }
                 $lastTime = \Yii::$app->formatter->asTimestamp(time()) - (int) \Yii::$app->comments2->securityRateLimitTime;
                 $messagesFind2->andWhere(['>=', 'created_at', $lastTime]);
                 //print_r($messagesFind2->createCommand()->rawSql);die;
                 if ($messagesFind2->count() >= \Yii::$app->comments2->securityRateLimitRequests) {
                     $rr->success = false;
                     $rr->message = \skeeks\cms\comments2\Module::t('app', 'You too often add comments.');
                     return $rr;
                 }
             }
             if ($model->save()) {
                 $rr->success = true;
                 if (\Yii::$app->comments2->enabledBeforeApproval == Cms::BOOL_Y) {
                     $rr->message = \Yii::$app->comments2->messageSuccessBeforeApproval;
                 } else {
                     $rr->message = \Yii::$app->comments2->messageSuccess;
                     //Отключена предмодерация, сразу публикуем
                     $model->status = Comments2Message::STATUS_ALLOWED;
                     $model->scenario = ActiveRecord::SCENARIO_DEFAULT;
                     $model->save();
                 }
                 $model->notifyCreate();
             } else {
                 $rr->success = false;
                 $rr->message = \skeeks\cms\comments2\Module::t('app', 'You comments not added') . ": " . implode(",", $model->getFirstErrors());
             }
         } else {
             $rr->success = false;
             $rr->message = \skeeks\cms\comments2\Module::t('app', 'You comments not added') . ": " . implode(",", $model->getFirstErrors());
         }
     }
     return $rr;
 }
<?php

/**
 * @author Semenov Alexander <*****@*****.**>
 * @link http://skeeks.com/
 * @copyright 2010 SkeekS (СкикС)
 * @date 14.07.2015
 */
/* @var $this yii\web\View */
/* @var $model \skeeks\cms\models\CmsContentElement */
$search = new \skeeks\cms\models\Search(\skeeks\cms\comments2\models\Comments2Message::className());
$dataProvider = $search->search(\Yii::$app->request->queryParams);
$dataProvider->query->andWhere(['element_id' => $model->id]);
?>

<?php 
echo $this->render('@skeeks/cms/comments2/views/admin-message/index', ['dataProvider' => $dataProvider, 'searchModel' => $search->getLoadedModel(), 'controller' => \Yii::$app->createController('/comments2/admin-message')[0], 'isOpenNewWindow' => true]);