/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Diputado::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(['id' => $this->id, 'partido_id' => $this->partido_id, 'tipo_eleccion' => $this->tipo_eleccion, 'periodo_inicio' => $this->periodo_inicio, 'periodo_fin' => $this->periodo_fin, 'edad' => $this->edad, 'distrito_id' => $this->distrito_id]); $query->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'apellido', $this->apellido])->andFilterWhere(['like', 'cunul', $this->cunul])->andFilterWhere(['like', 'correo', $this->correo])->andFilterWhere(['like', 'sexo', $this->sexo]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getDiputado() { return $this->hasOne(Diputado::className(), ['id' => 'diputado_id']); }
/** * @return \yii\db\ActiveQuery */ public function getDiputados() { return $this->hasMany(Diputado::className(), ['distrito_id' => 'id']); }
/** * Finds the Diputado model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Diputado the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Diputado::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }