public function actionCountryShow() { $query = Country::find(); $pagination = new Pagination(['defaultPageSize' => 5, 'totalCount' => $query->count()]); $countries = $query->orderBy('name')->offset($pagination->offset)->limit($pagination->limit)->all(); return $this->render('country-by-page', ['countries' => $countries, 'pagination' => $pagination]); }
public function actionCityList($id) { if ($countryCities = Country::findOne($id)) { foreach ($countryCities->cities as $city) { echo "<option value='" . $city->id . "'>" . $city->name . "</option>"; } } else { echo "<option> - </option>"; } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Country::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(['population' => $this->population]); $query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * Establishing hasOne relation with Country table * @return \yii\db\ActiveQuery */ public function getCountry() { return $this->hasOne(Country::classname(), ['country_id' => 'comment_country_id']); /*Сначала ключ другой таблицы, потом своей === или сначала ключ таблицы, которую пишем после hasOne hasMany*/ }
?> <?php echo $form->field($commentForm, 'comment_writer')->textInput(); ?> <?php echo $form->field($commentForm, 'comment_w_email'); ?> <?php echo $form->field($commentForm, 'comment_w_phone')->textInput(); ?> <?php echo $form->field($commentForm, 'country')->DropDownList(ArrayHelper::map(array_merge(Country::find()->all()), 'country_id', 'country_name'), ['prompt' => 'Select your country']); ?> <?php echo $form->field($commentForm, 'comment_w_gender')->inline()->radioList(['M' => 'Male', 'F' => 'Female'], ['options' => ['unselect' => null]]); ?> <?php echo $form->field($commentForm, 'comment_subject')->textInput(); ?> <?php echo $form->field($commentForm, 'comment_message')->textarea(); ?> <div class="form-group">
:</b> <?php echo $profile->last_name; ?> </p> <p><b><?php echo $profile->getAttributeLabel('gender'); ?> :</b> <?php echo $profile->gender ? 'Male' : 'Female'; ?> </p> <p><b><?php echo $profile->getAttributeLabel('country_id'); ?> :</b> <?php echo Country::findOne($profile->country_id)->name; ?> </p> <p><b><?php echo $profile->getAttributeLabel('city_id'); ?> :</b> <?php echo City::findOne($profile->city_id)->name; ?> </p> <p><b><?php echo $profile->getAttributeLabel('address'); ?> :</b> <?php echo $profile->address; ?>
/** * Finds the Country model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Country the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Country::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getCountry() { return $this->hasOne(Country::className(), ['id' => 'country_id']); }