/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Faculty::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(['faculty_id' => $this->faculty_id]); $query->andFilterWhere(['like', 'faculty_name', $this->faculty_name]); return $dataProvider; }
/** * Finds the Faculty model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Faculty the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Faculty::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getFaculty() { return $this->hasOne(Faculty::className(), ['faculty_id' => 'faculty_id']); }
public function getFaculty() { //a program belongs to one faculty return $this->hasOne(Faculty::className(), ['faculty_id' => 'faculty_id']); }
/* @var $this yii\web\View */ /* @var $model backend\models\Program */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="program-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'program_name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'faculty_id')->dropDownList(ArrayHelper::map(Faculty::find()->all(), 'faculty_id', 'faculty_name'), ['prompt' => 'Select Faculty']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>