public static function getBlockContent($id, $language) { /** @var Block $model */ $model = Block::findOne($id); return !is_null($model) ? $model->getContent($language, '') : ''; }
/** * Finds the Block model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Block the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Block::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionPage() { $request = Yii::$app->request; $block = null; if ($code = $request->get('code')) { $block = Block::find()->where(['url_code' => $code])->one(); if (is_null($block)) { $block = Block::findOne($code); } } if (!is_null($block)) { return $this->render('page', ['model' => $block]); } else { return $this->goHome(); } }
/** * Finds the Block model based on its slug value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $slug * @return Block the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModelBySlug($slug) { if (($model = Block::findOne(['slug' => $slug])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Finds the Link model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Link the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Block::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('app', 'PAGE_NOT_FOUND')); } }
<?php use app\models\Block; /** @var $id string */ /** @var Block $block */ $block = Block::findOne($id); if (!is_null($block)) { ?> <div class="block_<?php echo $id; ?> "> <?php echo $block->getContent(Yii::$app->language); ?> </div> <?php }