/** @inheritdoc */ public function bootstrap($app) { /** @var Module $module */ /** @var \yii\db\ActiveRecord $modelName */ if ($app->hasModule('website-comments') && ($module = $app->getModule('website-comments')) instanceof Module) { Yii::$container->setSingleton(WebsiteCommentsFinder::className(), ['commentQuery' => \jarrus90\WebsiteComments\Models\Comment::find()]); if (!isset($app->get('i18n')->translations['website-comments*'])) { $app->get('i18n')->translations['website-comments*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages', 'sourceLanguage' => 'en-US']; } if (!$app instanceof ConsoleApplication) { $module->controllerNamespace = 'jarrus90\\WebsiteComments\\Controllers'; $configUrlRule = ['prefix' => $module->urlPrefix, 'rules' => $module->urlRules]; if ($module->urlPrefix != 'website-comments') { $configUrlRule['routePrefix'] = 'website-comments'; } $configUrlRule['class'] = 'yii\\web\\GroupUrlRule'; $rule = Yii::createObject($configUrlRule); $app->urlManager->addRules([$rule], false); $app->params['admin']['menu']['website-comments'] = function () use($module) { return $module->getAdminMenu(); }; } else { if (empty($app->controllerMap['migrate'])) { $app->controllerMap['migrate']['class'] = 'yii\\console\\controllers\\MigrateController'; } $app->controllerMap['migrate']['migrationNamespaces'][] = 'jarrus90\\WebsiteComments\\migrations'; } } }
public function actionIndex() { $form = Yii::createObject(['class' => Comment::className(), 'scenario' => 'create', 'item' => Yii::createObject(['class' => Comment::className(), 'from_id' => Yii::$app->user->id])]); $this->performAjaxValidation($form); if ($form->load(Yii::$app->request->post()) && $form->save()) { return $this->refresh(); } $filterModel = Yii::createObject(['class' => Comment::className(), 'scenario' => 'search']); $request = Yii::$app->request->get(); $request['parent_id'] = NULL; $request['is_blocked'] = false; $dataProvider = $filterModel->search($request, true); Yii::$app->view->title = Yii::t('website-comments', 'Comments'); return $this->render('index', ['filterModel' => $filterModel, 'dataProvider' => $dataProvider, 'form' => $form]); }
/** * Get list of childs * @return Comment[] */ public function getChilds() { return $this->hasMany(Comment::className(), ['parent_id' => 'id']); }