Beispiel #1
0
 /**
  * Список городов для выбора
  * @return array|\yii\db\ActiveRecord[]
  */
 public static function getAllCities()
 {
     $query = Review::find()->distinct()->joinWith('cities')->select('city.*')->where(['IS NOT', 'city.id', null])->orderBy('city.name')->asArray();
     if (!Yii::$app->user->isGuest) {
         return $query->all();
     } else {
         return Yii::$app->db->cache(function ($db) use($query) {
             return $query->all();
         }, Yii::$app->params['dbCacheValidTime']);
     }
 }
Beispiel #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdReview()
 {
     return $this->hasOne(Review::className(), ['id' => 'id_review']);
 }
 /**
  * Поиск отзыва по ключу
  * @param integer $id
  * @return Review the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (!Yii::$app->user->isGuest) {
         $model = Review::findOne($id);
     } else {
         $model = Yii::$app->db->cache(function ($db) use($id) {
             return Review::findOne($id);
         }, Yii::$app->params['dbCacheValidTime']);
     }
     if ($model !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }