/** * Finds the City model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return City the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = City::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = City::find()->where('active!=3'); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['IDcity' => $this->IDcity, 'active' => $this->active]); $query->andFilterWhere(['like', 'city', $this->city]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getIDcity() { return $this->hasOne(City::className(), ['IDcity' => 'IDcity']); }
use yii\helpers\Html; use yii\widgets\ActiveForm; use app\modules\admin\models\City; /* @var $this yii\web\View */ /* @var $model app\modules\admin\models\Station */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="station-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $model->formRelationalDropDown($form, 'IDcity', City::find()->where('active!=3')->all(), 'IDcity', 'city'); ?> <?php echo $form->field($model, 'station')->textInput(['maxlength' => 50]); ?> <?php echo $model->formActiveDropDown($form); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div>
<?php use yii\helpers\Html; use yii\grid\GridView; use app\modules\admin\models\City; /* @var $this yii\web\View */ /* @var $searchModel app\modules\admin\models\StationSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('app', 'Stations'); ?> <div class="station-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <p> <?php echo $searchModel->createButton(); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'station', $searchModel->gridRelationalColumn('IDcity', City::find()->where('active!=3')->all(), 'IDcity', 'city'), $searchModel->gridActiveColumn(), $searchModel->actionColumn()]]); ?> </div>