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 @@ + +