static function TabAd($tab) { if (!($TabAd = Yii::$app->cache->get('TabAd' . $tab))) { $TabModel = Tab::findOne(['enname' => $tab]); if (!empty($TabModel->id)) { $TabAd = TabAd::find()->where(['tab_id' => $TabModel->id])->asArray()->all(); Yii::$app->cache->set('TabAd' . $tab, $TabAd, 0); } else { return null; } } return $TabAd; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = TabAd::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, 'tab_id' => $this->tab_id, 'status' => $this->status]); $query->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
/** * Finds the TabAd model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return TabAd the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = TabAd::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?php use yii\helpers\Markdown; $TabAd = \common\models\TabAd::TabAd(Yii::$app->session->get('tab')); if (!empty($TabAd)) { ?> <section> <div class="block-content markdown-content"> <?php foreach ($TabAd as $ad) { ?> <?php echo $ad['content']; ?> <?php } ?> </div> </section> <?php }