/** * Displays a single Page model. * @param integer $id * @return mixed */ public function actionView($id) { $model = $this->findModel($id); $child_pages_q = Page::find()->joinWith('page_rel')->where(['page_self_rels.parent_page_id' => $id])->all(); $breadcumb = array_reverse(Page::get_breadcumb($id)); $child_pages = array(); if (!empty($child_pages_q)) { foreach ($child_pages_q as $key) { $child_count = Page::find()->joinWith('page_rel')->where(['page_self_rels.parent_page_id' => $key->id])->count(); $key->child_count = $child_count; array_push($child_pages, $key); } } MyGlobalClass::log_activity('Visited page - ID: ' . $model->id . ' and page title: ' . $model->page_title); return $this->render('view', ['model' => $model, 'child_pages' => $child_pages, 'breadcumb' => $breadcumb]); }
/** * Creates a new Page model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Page(); $PageSelfRels_model = new PageSelfRels(); $PageTypeRel_model = new PageTypeRel(); $_SESSION['KCFINDER']['disabled'] = false; // enables the file browser in the admin $_SESSION['KCFINDER']['uploadURL'] = Url::base() . "/kcupload/"; // URL for the uploads folder $_SESSION['KCFINDER']['uploadDir'] = Yii::getAlias('@app') . "/web/kcupload/"; // path to the uploads folder if ($model->load(Yii::$app->request->post()) && $PageSelfRels_model->load(Yii::$app->request->post()) && $PageTypeRel_model->load(Yii::$app->request->post())) { if ($model->save()) { $PageSelfRels_model->page_id = $model->id; if ($PageSelfRels_model->parent_page_id == '') { $PageSelfRels_model->parent_page_id = array(0); } $PageTypeRel_model->page_id = $model->id; if ($PageTypeRel_model->page_type == '') { $PageTypeRel_model->page_type = array(''); } if (Page::update_page_self_rel($PageSelfRels_model) && Page::update_page_type_rel($PageTypeRel_model)) { MyGlobalClass::log_activity('Created page - ID: ' . $model->id . ' and page title: ' . $model->page_title); return $this->redirect(['view', 'id' => $model->id]); } else { var_dump($PageSelfRels_model->getErrors()); } } else { var_dump($model->getErrors()); } } else { return $this->render('create', ['model' => $model, 'PageSelfRels_model' => $PageSelfRels_model, 'PageTypeRel_model' => $PageTypeRel_model]); } }