Beispiel #1
0
 public function getCity()
 {
     return $this->hasOne(Cities::className(), ['city_id' => 'city_id']);
 }
 public function actionCities()
 {
     $country_id = (int) \Yii::$app->request->getQueryParam('country_id');
     if ($country_id) {
         $cities = Cities::find()->where(['country_id' => $country_id])->all();
     } else {
         $cities = Cities::find()->all();
     }
     $result = [];
     if ($cities) {
         /** @var Cities $city */
         foreach ($cities as $city) {
             $result[] = ArrayHelper::toArray($city);
         }
     }
     return json_encode($result);
 }