From c9513f031afd3c925350fd486acfa1c0c1d46e42 Mon Sep 17 00:00:00 2001 From: Egorka Date: Thu, 5 Jul 2018 16:29:46 +0300 Subject: [PATCH] Dashboard search Search Performance Frontend blog tags showing fix --- backend/controllers/SiteController.php | 41 ++++++++++++++++++-- backend/messages/ru/main.php | 1 + backend/views/layouts/left.php | 45 +++++++++++++++++----- backend/views/site/search.php | 41 ++++++++++++++++++++ common/bootstrap/SetUp.php | 5 +++ common/modules/blog/BlogModule.php | 7 ++++ common/modules/blog/urls/BlogTagUrlRule.php | 4 +- common/modules/blog/views/post/post.php | 1 - console/controllers/SearchInitController.php | 20 ++++++++++ core/components/SearchPerformance.php | 19 +++++++++ core/entities/Search.php | 26 +++++++++++++ core/forms/SearchForm.php | 21 ++++++++++ .../themes/start/modules/blog/views/post/post.php | 2 +- 13 files changed, 216 insertions(+), 17 deletions(-) create mode 100644 backend/views/site/search.php create mode 100644 console/controllers/SearchInitController.php create mode 100644 core/components/SearchPerformance.php create mode 100644 core/entities/Search.php create mode 100644 core/forms/SearchForm.php diff --git a/backend/controllers/SiteController.php b/backend/controllers/SiteController.php index cac991f..1c4d5e1 100644 --- a/backend/controllers/SiteController.php +++ b/backend/controllers/SiteController.php @@ -1,7 +1,10 @@ [ - 'class' => AccessControl::className(), + 'class' => AccessControl::class, 'rules' => [ [ 'actions' => ['error'], 'allow' => true, ], [ - 'actions' => ['index'], + 'actions' => ['index', 'search'], 'allow' => true, 'roles' => ['Dashboard'], ], @@ -37,7 +40,7 @@ class SiteController extends Controller ], ], 'verbs' => [ - 'class' => VerbFilter::className(), + 'class' => VerbFilter::class, 'actions' => [ 'logout' => ['post'], ], @@ -67,6 +70,38 @@ class SiteController extends Controller return $this->render('index'); } + public function actionSearch() + { + $form = new SearchForm(); + + if ($form->load(Yii::$app->request->post()) && $form->validate()) { + try { + $query = Search::find() + ->andWhere(['LIKE', 'title', $form->query]) + ->orWhere(['LIKE', 'content', $form->query]); + + $provider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => [ + 'pageSize' => 10, + ], + 'sort' => [], + ]); + + return $this->render('search', [ + 'provider' => $provider, + 'form' => $form + ]); + + //$page = $this->service->create($form); + //return $this->redirect(['view', 'id' => $page->id]); + } catch (\DomainException $e) { + //Yii::$app->errorHandler->logException($e); + //Yii::$app->session->setFlash('error', $e->getMessage()); + } + } + } + public function beforeAction($action) { if ($action->id === 'error') { diff --git a/backend/messages/ru/main.php b/backend/messages/ru/main.php index bf7bb3a..cfe0f46 100644 --- a/backend/messages/ru/main.php +++ b/backend/messages/ru/main.php @@ -25,4 +25,5 @@ return [ 'Editing' => 'Редактирование', 'Change at your own risk' => 'Редактируйте на свой страх и риск', 'Online' => 'В сети', + 'Search results' => 'Поиск', ]; \ No newline at end of file diff --git a/backend/views/layouts/left.php b/backend/views/layouts/left.php index 0211685..2a11b15 100644 --- a/backend/views/layouts/left.php +++ b/backend/views/layouts/left.php @@ -1,3 +1,13 @@ + +