/** * finds and return content of requested block by name * @param $name * @param bool $isGlobal * @return bool|string * @throws BadRequestHttpException */ public function loadBlock($name, $isGlobal = false) { if (is_null($name)) { throw new BadRequestHttpException('Block name not specified.'); } $find = ['title' => $name]; if ($isGlobal === false) { //if not global if (isset($this->params['block']['id'])) { $find['parent'] = $this->params['block']['id']; } if (isset($this->params['block']['layout'])) { $find['parent_layout'] = $this->params['block']['layout']; } if (isset($this->params['block']['slug'])) { //get parent page id /** * @var $page \backend\models\Page */ if ($page = Page::findOne(['slug' => $this->params['block']['slug']])) { $find['parent'] = $page->id; } } } /** * @var $block \backend\models\Block */ if ($block = Block::findOne($find)) { //if block found return $block->render(); } return false; }
/** * Finds the Page model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Page the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Page::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }