protected function findModel($id) { if (($model = Page::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Displays a single Cms model. * @param integer $id * @return mixed */ public function actionView($id) { $model = $this->findModel($id); $pagedata = Page::findOne($model->pageid); $cmspoaitiondata = Cmsposition::findOne($model->cmspositionid); $model->pageid = $pagedata->name; $model->cmspositionid = $cmspoaitiondata->name; //$model->imgurl = Yii::$app->request->hostInfo.'/'.$model->imgurl; return $this->render('view', ['model' => $model]); }
/** * @param $id * @return \yii\web\Response * @throws NotFoundHttpException * @throws \Exception */ public function actionDelete($id) { /** @var Page $model */ $model = Page::findOne($id); if (!$model) { throw new NotFoundHttpException(); } $model->delete(); return $this->redirect(['list']); }
public function run() { if (strpos(\Yii::$app->request->url, "view-post")) { $post = Post::findOne(\Yii::$app->request->get('id')); $current_page = $post->page; } else { if (strpos(\Yii::$app->request->url, "view-album")) { $photo = Photo::findOne(\Yii::$app->request->get('id')); $current_page = $photo->page; } else { $slug = \Yii::$app->request->get('slug'); $current_page = Page::find()->where(['slug' => $slug])->one(); } } $parent = $current_page->parent_id == 0 ? null : Page::findOne($current_page->parent_id); return $this->render('breadCrumb', ['parent' => $parent, 'current_page' => $current_page]); }
public function getParent() { return Page::findOne(['id' => $this->parent_id]); }
/** * Finds the Page model based on its slug value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $slug * @return Page the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModelBySlug($slug) { if (($model = Page::findOne(['slug' => $slug])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionViewPage($id) { $page = Page::findOne($id); return $this->redirect(['site/page', 'slug' => $page->slug]); }
/** * Creates a new Photo model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Photo(); $request = Yii::$app->request; $page_id = $request->get('page_id'); $model->create_date = time(); $model->update_date = time(); if ($model->load(Yii::$app->request->post())) { $model->page_id = $page_id; $model->parent_id = 0; $model->create_date = strtotime($model->create_date); $model->update_date = strtotime($model->update_date); if ($model->save()) { return $this->redirect(['view', 'id' => $model->id, 'page_id' => $page_id]); } } $page = Page::findOne($page_id); return $this->render('create', ['model' => $model, 'page_id' => $page_id, 'page' => $page]); }