/** * Saved edited page; called viea ajax * @return String */ public function postSavePage() { $okay = true; $page_id = $_REQUEST['page_id']; $page_content = $_REQUEST['thedata']; if ($page_id > 0) { $page = Page::find($page_id); } else { $page = new Page(); $slugify = new Slugify(); $browser_title = $_REQUEST['browser_title']; $page->browser_title = $browser_title; $page->slug = $slugify->slugify($browser_title); // verify that the slug is not already in the db $results = Page::where('slug', $slugify->slugify($browser_title))->get(); foreach ($results as $result) { $okay = false; } } $page->page_content = $page_content; if ($okay) { $page->save(); echo "OK"; } else { echo "Browser title is already in use"; } }
public function actionIndex() { $request = Yii::$app->request; $page_id = $request->get('page_id'); $search = $request->get('search'); $columns = Page::find()->where(['type' => 4])->all(); if ($search) { $query = Photo::find()->where(['like', 'title', $search]); $countQuery = clone $query; $pnation = new Pagination(['defaultPageSize' => 10, 'totalCount' => $countQuery->count()]); $photo = $query->orderBy(['create_date' => SORT_DESC])->offset($pnation->offset)->limit($pnation->limit)->all(); return $this->render('index', ['page_id' => $page_id, 'pnation' => $pnation, 'post' => $post, 'columns' => $columns]); } if ($page_id) { $query = Photo::find()->where(['page_id' => $page_id, 'parent_id' => 0]); $countQuery = clone $query; $pnation = new Pagination(['defaultPageSize' => 10, 'totalCount' => $countQuery->count()]); $photo = $query->orderBy(['create_date' => SORT_DESC])->offset($pnation->offset)->limit($pnation->limit)->all(); } else { $query = Photo::find()->where(['parent_id' => 0])->andWhere(['>', 'page_id', 1]); $countQuery = clone $query; $pnation = new Pagination(['defaultPageSize' => 10, 'totalCount' => $countQuery->count()]); $photo = $query->orderBy(['create_date' => SORT_DESC])->offset($pnation->offset)->limit($pnation->limit)->all(); } return $this->render('index', ['page_id' => $page_id, 'pnation' => $pnation, 'photo' => $photo, 'columns' => $columns]); }
public function destroy($id) { $page = Page::find($id); //$page->delete(); Notification::success('The page was deleted.'); return Redirect::route('admin.pages.index'); }
public function run() { $menu = Menu::find()->where(['position' => 'bottom'])->one(); $p = explode(',', $menu->content); $model = Page::find()->where(['id' => $p])->all(); return $this->render('links', ['pages' => $model]); }
/** * Displays a single Post model. * @param integer $id * @return mixed */ public function actionView($name) { $pages = Page::find()->all(); foreach ($pages as $key => $value) { $menuItems[] = ['label' => $value->name, 'url' => ['page/view', 'name' => $value->name]]; } return $this->render('view', ['model' => $this->findModel($name), 'pages' => $pages, 'menuItems' => $menuItems]); }
public function actionSlug($slug) { $model = Page::find()->where(['slug' => $slug])->one(); if (!is_null($model)) { return $this->render('view', ['model' => $model]); } else { return $this->redirect('index'); } }
/** * Creates data provider instance with search query applied * @return ActiveDataProvider */ public function search($params) { $query = Page::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'status' => $this->status]); $query->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'body', $this->body]); return $dataProvider; }
public function search($params) { $query = Page::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'seo_title', $this->seo_title])->andFilterWhere(['like', 'seo_keywords', $this->seo_keywords])->andFilterWhere(['like', 'seo_description', $this->seo_description]); return $dataProvider; }
public function __construct() { $this->setting = Settings::getSetting(); View::share('listNewPd', $this->_getNewProduct()); View::share('listNewsTop', $this->_getNewsTop()); View::share('Category', $this->getCategoryShowInIndex()); View::share('menu_provider', $this->getProviderShowInIndex()); View::share('setting', $this->setting); View::share('guideDes', Page::find(4)); View::share('title', ""); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Page::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'image_id' => $this->image_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'lang', $this->lang]); return $dataProvider; }
public function actionView($alias) { $this->layout = 'main'; $model = Page::find()->where(['alias' => $alias, 'status' => Page::STATUS_PUBLISHED, 'lang' => Yii::$app->language])->one(); if (!$model) { $model = Page::find()->where(['alias' => $alias, 'status' => Page::STATUS_PUBLISHED, 'lang' => Yii::$app->sourceLanguage])->one(); if (!$model) { throw new NotFoundHttpException(Yii::t('page', 'Page not found')); } } return $this->render('view', ['model' => $model]); }
/** * Action that displays pages list * @return string */ public function actionIndex() { $pages = Page::find()->orderBy(['created_at' => SORT_DESC]); $count = Yii::$app->cache->lazy(function () use($pages) { return $pages->count(); }, 'PagesCount', 86400, Page::commonTag()); $pagination = new Pagination(['totalCount' => $count]); $pages = Yii::$app->cache->lazy(function () use($pages, $pagination) { return $pages->offset($pagination->offset)->limit($pagination->limit)->all(); }, "Pages:{$pagination->offset}:{$pagination->limit}", 86400, Page::commonTag()); return $this->render('index', ['pages' => $pages, 'pagination' => $pagination]); }
/** * Updates an existing Menu model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $pages = Page::find()->all(); if ($model->load(Yii::$app->request->post())) { $menu->content = implode(',', $menu->content); if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('update', ['model' => $model, 'pages' => $pages]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Page::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'live' => $this->live, 'date_updated' => $this->date_updated, 'date_published' => $this->date_published]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
public function run() { $menu = Menu::find()->where(['position' => 'top'])->one(); $p = explode(",", $menu->content); $pages = Page::find()->where(['id' => $p])->all(); if (strpos(\Yii::$app->request->url, "view-post")) { $post = Post::findOne(\Yii::$app->request->get('id')); $current_page = $post->page; } else { $slug = \Yii::$app->request->get('slug'); $current_page = Page::find()->where(['slug' => $slug])->one(); } return $this->render('nav', ['pages' => $pages, 'current_page' => $current_page]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Page::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * @param $params * @return ActiveDataProvider */ public function search($params) { $query = Page::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_ASC], 'attributes' => ['id', 'name', 'slug', 'status', 'is_system']]]); $this->load($params); if (!$this->validate()) { $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['status' => $this->status, 'is_system' => $this->is_system]); $query->andFilterWhere(['like', 'name', $this->name]); $query->andFilterWhere(['like', 'slug', $this->slug]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Page::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created' => $this->created]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'img', $this->img]); return $dataProvider; }
public function actionShow() { if (isset($_GET['name'])) { $name = $_GET['name']; $lang = \Yii::$app->language; //echo $name . ' - ' .$lang; $model = Page::find()->where(['name' => $name, 'lang' => $lang])->one(); if ($model !== null) { //var_dump($model); return $this->render('show', ['model' => $model]); } } return $this->render('page_not_found'); }
public function run() { $menu = Menu::find()->where(['position' => 'top'])->one(); $p = explode(',', $menu->content); $model = Page::find()->orderBy('display_order asc')->all(); $pages = $this->tree($model, 0, $p); if (strpos(\Yii::$app->request->url, "view-post")) { $post = Post::findOne(\Yii::$app->request->get('id')); $current_page = $post->page; } else { $slug = \Yii::$app->request->get('slug'); $current_page = Page::find()->where(['slug' => $slug])->one(); } return $this->render('cateWidget', ['pages' => $pages, 'current_page' => $current_page]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Page::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created' => $this->created, 'updated' => $this->updated]); $query->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'template', $this->template])->andFilterWhere(['like', 'lang', $this->lang])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'h1', $this->h1])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'keywords', $this->keywords])->andFilterWhere(['like', 'text', $this->text]); return $dataProvider; }
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 index($page_url = null) { if (isset($page_url)) { try { $page = Page::where('url', '=', $page_url)->firstOrFail(); } catch (ModelNotFoundException $e) { return view('errors.404'); } if (!$page->keywords || !$page->description) { $main_page = Page::find(1); $page->keywords = $page->keywords ? $page->keywords : $main_page->keywords; $page->description = $page->description ? $page->description : $main_page->description; unset($main_page); } return view('page', ['page' => $page, 'menu' => $this->menu]); } else { return redirect()->route('index'); } }
/** * @return Page */ public function getPage() { if ($this->_page == null) { $controller = $this->owner; if ($controller->id == 'pages' && $controller->action->id == 'view') { //get request params $queryParams = Yii::$app->getRequest()->getQueryParams(); $this->_page = Page::find()->where(array('controller' => $controller->id, 'action' => $controller->action->id, 'id' => $queryParams['id']))->one(); } if ($this->_page == null) { $this->_page = Page::find()->where(array('controller' => $controller->id, 'action' => $controller->action->id))->one(); } if ($this->_page == null) { $this->_page = $this->autoCreatePage(null, false); } } $this->owner->layout = $this->_page->layout->fullPath; return $this->_page; }
/** * Define your route model bindings, pattern filters, etc. * * @return void */ public function boot() { parent::boot(); Route::bind('article', function ($slug) { if (!Auth::user()) { return Article::published()->slug($slug)->first(); } return Article::where('slug', $slug)->first() ?: Article::findOrFail((int) $slug); }); Route::bind('tag', function ($slug) { if (!Auth::user()) { return Tag::slug($slug)->first(); } return Tag::where('slug', $slug)->first() ?: Tag::findOrFail((int) $slug); }); Route::bind('page', function ($id) { return Page::find($id); }); }
/** * ------------------------------------------------- * 获取正确的评论对象 * ------------------------------------------------- */ public static function tableObj($post_id, $type) { //方法一,让客户端控制 //Comment::addTableObj('\App\Models\Article'); //Comment::addTableObj('\App\Models\Goods'); /** foreach(self::$tableObjs as $tobj){ if($type == $tobj::commentType() && $post_id)return $tobj::find($post_id); } */ //方法二,服务器控制 if ($type == 1) { return Goods::find($post_id); } elseif ($type == 2) { return Article::find($post_id); } elseif ($type == 3) { return Page::find($post_id); } return null; }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $menu = Page::find($id); $menu->delete(); return redirect('admin/pages'); }
public function run() { $model = Page::find()->where(['slug' => $this->slug])->one(); return $this->render('block', ['model' => $model]); }
public function pageMain() { $main_page = Page::find(1); return view('admin.pages.main', ['content' => $main_page->content]); }
/** * Deletes an existing News model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $model = Page::findOne($id); $models = Page::find()->where(['name' => $model->name])->all(); foreach ($models as $m) { $m->delete(); } return $this->redirect(['index']); }