/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($idevento) { $query = EventoHasVoluntario::find()->where(['evento_idevento' => $idevento]); $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(['evento_idevento' => $this->evento_idevento, 'voluntario_idvoluntario' => $this->voluntario_idvoluntario]); return $dataProvider; }
/** * Finds the EventoHasVoluntario model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $evento_idevento * @param integer $voluntario_idvoluntario * @return EventoHasVoluntario the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($evento_idevento, $voluntario_idvoluntario) { if (($model = EventoHasVoluntario::findOne(['evento_idevento' => $evento_idevento, 'voluntario_idvoluntario' => $voluntario_idvoluntario])) !== null) { return $model; } else { throw new NotFoundHttpException('Página não Encontrada'); } }
/** * @return \yii\db\ActiveQuery */ public function getEventoHasVoluntarios() { return $this->hasMany(EventoHasVoluntario::className(), ['voluntario_idvoluntario' => 'idvoluntario']); }
public function searchVoluntarios() { $id_evento = Yii::$app->request->post('evento_idevento'); if (!Yii::$app->user->isGuest) { //$query = ItemProgramacao::find()->where(['evento_idevento' => $id_evento]); $query = EventoHasVoluntario::find()->where(['evento_idevento' => $id_evento])->innerJoin('voluntario', 'voluntario.idvoluntario = evento_has_voluntario.voluntario_idvoluntario')->orderBy('voluntario.nome'); } else { return Yii::$app->getResponse()->redirect(array('/evento/', NULL)); // é redirecionado a tela de eventos, se não estiver logado } $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; } return $dataProvider; }