<p> <?php echo Html::a('Create Aluno', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'alun_codigo', 'alun_nome', 'alun_matricula', 'alun_data_nascimento', 'alun_habilitado:boolean', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div> <?php use app\models\Aluno; use app\models\Estado; //$model = new Aluno(); //$model->alun_nome = "Francisco"; //$model->alun_matricula = "23423"; //$model->alun_data_nascimento = "09/09/1999"; //$model->muni_codigo = 1; //$model->esta_codigo = 1; //$model->save(); // //print_r($model->errors); $estado = Estado::findOne(1); echo $estado->esta_nome . "<br>"; foreach ($estado->municipios as $municipio) { echo $municipio->muni_nome . "<br>"; }
/** * Finds the Estado model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Estado the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Estado::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionEstado($id) { $estado = \app\models\Estado::findOne($id); return $estado; }