public function printaMunicipios($id)
 {
     $variosMuni = Municipio::model()->findAllByAttributes(array('regional_id' => $id));
     $result = '';
     foreach ($variosMuni as $mun) {
         if (Cursista::model()->exists('municipio_id = :municipio_id', array('municipio_id' => $mun->id))) {
             $modelo = $mun;
             $result .= $mun->nome . '<br />';
         }
     }
     if (empty($modelo)) {
         $result = 'Não existem municípios concluintes ainda.';
     }
     return $result;
 }
Ejemplo n.º 2
0

<h1>Escolha um município do Estado</h1>

<?php 
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'municipio-pesquisa-form', 'htmlOptions' => array('class' => 'well'), 'type' => 'horizontal'));
?>

    <legend>Pesquisar concluintes do curso por Município</legend>
    
    <?php 
?>
    
    <?php 
$municipios = CHtml::listData(Municipio::model()->findAll(), 'id', 'nome');
echo $form->dropDownListRow($model, 'id', $municipios);
?>
<div class="form-actions">
    <?php 
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'link', 'label' => 'Voltar', 'icon' => 'icon-chevron-left', 'url' => Yii::app()->baseUrl));
?>
    <?php 
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'label' => 'Pesquisar', 'icon' => 'icon-search'));
?>
</div>    

<?php 
$this->endWidget();
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Municipio::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }