Ejemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Concelho::find();
     $query->joinWith('relIdDistrito');
     // add conditions that should always apply here
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['idConcelho' => $this->idConcelho]);
     $query->andFilterWhere(['like', 'Concelho.nome', $this->nome])->andFilterWhere(['like', 'Distrito.nome', $this->idDistrito]);
     return $dataProvider;
 }
Ejemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getConcelhos()
 {
     return $this->hasMany(Concelho::className(), ['idDistrito' => 'idDistrito']);
 }
Ejemplo n.º 3
0
<div class="cod-postal-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'codigo')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'localidade')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'idConcelho')->dropDownList(ArrayHelper::map(Concelho::find()->all(), 'idConcelho', 'nome'), ['prompt' => 'Escolher Concelho']);
?>

    <?php 
echo $form->field($model, 'idDistrito')->dropDownList(ArrayHelper::map(Distrito::find()->all(), 'idDistrito', 'nome'), ['prompt' => 'Escolher Distrito']);
?>
    
    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Criar' : 'Atualizar', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>
Ejemplo n.º 4
0
 /**
  * Finds the Concelho model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Concelho the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Concelho::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRelIdConcelho()
 {
     return $this->hasOne(Concelho::className(), ['idConcelho' => 'idConcelho']);
 }