public function show($url) { $travel = Travel::where('url', $url)->first(); if ($travel) { return view('travels.show', ['travel' => $travel]); } return view('errors.404'); }
/** * 生成sitemap地图 * @return \Illuminate\Http\Response */ public function sitemap() { $data = Cache::remember('sitemap', 30, function () { return ['travels' => Travel::all(), 'destinations' => Destination::all()]; }); $travels = $data['travels']; $destinations = $data['destinations']; $data = compact('travels', 'destinations'); $sitemap = view('index.sitemap', $data); return Response($sitemap, '200')->header('Content-Type', 'text/xml'); }
public function destroy($id) { $travel = Travel::find($id); if ($travel) { $travel->delete(); flash('Элемент удалён'); return Redirect::back(); } flash('Ошибка'); return Redirect::back(); }
public function actionUpdate_travel($id) { $model = Travel::findOne($id); // คล้ายๆกับ isset($_POST); แต่แบบนี้ดีกว่า เพราะอันนี้มีค่าแล้วมันเข้ามาตลอด แต่แบบที่ใช้อยู่ไม่เข้า if (Yii::$app->request->post()) { $model->user = $_POST['Register']['user']; $model->email = $_POST['Register']['email']; $model->password = $_POST['Register']['password']; $model->sex = $_POST['Register']['sex']; $model->create_date = $_POST['Register']['create_date']; // or //$model->load(\Yii::$app->request->post()); if ($model->save()) { return $this->redirect(['register/view_travel']); } } return $this->render('update_travel', ['model' => $model]); }
/** * 游记详情 * @param $slug string * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function travelDetail($slug) { $data = Cache::remember("travel.detail.{$slug}", self::CACHE_TIME, function () use($slug) { $destinationList = $this->destination->getList(12); $detail = $this->travel->where('slug', $slug)->firstOrFail(); $detail->content = Markdown::convertToHtml($detail->content); $destinationInfo = $detail->destination; $travelList = $this->travel->where('destination_id', $destinationInfo['id'])->where('id', '<>', $detail->id)->latest('begin_date')->take(5)->get(); //10篇同目的地的最新游记 $travelList = !$travelList->isEmpty() ? $travelList : ''; return ['destinationList' => $destinationList, 'destinationInfo' => $destinationInfo, 'detail' => $detail, 'travelList' => $travelList]; }); $destinationList = $data['destinationList']; $destinationInfo = $data['destinationInfo']; $detail = $data['detail']; $travelList = $data['travelList']; $seoSuffix = "_{$destinationInfo->destination}游记_tanteng.me"; return view('travel.detail', compact('detail', 'destinationList', 'destinationInfo', 'travelList', 'seoSuffix')); }
/** * @return \yii\db\ActiveQuery */ public function getTravels() { return $this->hasMany(Travel::className(), ['tra_type' => 'id']); }
public function actionSingle_travel($id) { $this->layout = 'bank'; $id_travel = $id - 1; $travel = Travel::find()->all(); $type_travel = TypeTravel::find()->all(); $image = ImageTravel::find()->all(); $id_image = IdImgTravel::find()->all(); $idPathImage = IdImgTravel::find()->where(['travel_id' => $id])->all(); return $this->render('single_travel', ['id_travel' => $id_travel, 'travel' => $travel, 'image' => $image, 'id_image' => $image, 'idPathImage' => $idPathImage, 'type_travel' => $type_travel]); }
public function actionView_travel() { $this->layout = 'bank'; $travel = Travel::find()->all(); return $this->render('view_travel', ['travel' => $travel]); }