/** * Show the application welcome screen to the user. * * @return Response */ public function index() { $main = MainPage::find(1); if (!$main) { abort(404); } return view('static.welcome', ['p' => 'main', 'text' => $main->text, 'l_p_text' => $main->l_p_text, 'r_p_text' => $main->r_p_text]); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(Request $request, $id) { try { $mainPage = MainPage::findOrFail($id); } catch (ModelNotFoundException $e) { abort(404); } $validationRules = ['text' => 'required', 'l_p_text' => 'required', 'r_p_text' => 'required']; $v = Validator::make($request->all(), $validationRules); if ($v->fails()) { return redirect()->back()->withErrors($v->errors())->withInput(); } $mainPage->text = $request->text; $mainPage->l_p_text = $request->l_p_text; $mainPage->r_p_text = $request->r_p_text; $mainPage->save(); return redirect('pageTexts')->with('alert-success', 'Текст на Главной странице изменен'); }
<?php /** @var \app\models\Video $videos */ /** @var \app\models\PhotoCatalog $photos */ /** @var \yii\web\View $this */ use app\components\MyHelper; use evgeniyrru\yii2slick\Slick; use yii\helpers\Html; use yii\web\JsExpression; ?> <?php $dataPage = \app\models\MainPage::findOne(1); $this->title = $dataPage->meta_title; // $this->registerMetaTag([ // 'name' => 'keywords', // 'content' => $dataPage->meta_keywords // ]); $this->registerMetaTag(['name' => 'description', 'content' => $dataPage->meta_description]); ?> <div class="g w1140 main"> <!-- slider --> <div class="herounit blue-gradient-bg"> <div class="g w1140 slider"> <a href="#"><img class="r" src="/images/slide-01.png" alt=""></a> <?php // $images = [ // Html::a(Html::img("http://goods.marketgid.com/img/new-year.jpg", ['alt' => 'Для праздников и карнавалов', 'title' => 'Для праздников и карнавалов']), ['category/dla_prazdnikov_i_karnavalov/2054']), // Html::a(Html::img("http://goods.marketgid.com/img/appliances.png", ['alt' => 'Бытовая техника', 'title' => 'Бытовая техника']), ['category/bytovaa_tehnika/8']), // Html::a(Html::img("http://goods.marketgid.com/img/auto.png", ['alt' => 'Автотовары', 'title' => 'Автотовары']), ['category/avto_velo_moto/6']),
/** * Finds the MainPage model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return MainPage the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = MainPage::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }