本文整理汇总了PHP中app\models\Page::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Page::findOne方法的具体用法?PHP Page::findOne怎么用?PHP Page::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Page
的用法示例。
在下文中一共展示了Page::findOne方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findModel
protected function findModel($id)
{
if (($model = Page::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例2: actionView
/**
* 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]);
}
示例3: actionDelete
/**
* @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']);
}
示例4: run
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]);
}
示例5: getParent
public function getParent()
{
return Page::findOne(['id' => $this->parent_id]);
}
示例6: findModelBySlug
/**
* 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.');
}
}
示例7: actionViewPage
public function actionViewPage($id)
{
$page = Page::findOne($id);
return $this->redirect(['site/page', 'slug' => $page->slug]);
}
示例8: actionCreate
/**
* 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]);
}