/** * Displays a single User model. * @param integer $id * @return mixed */ public function actionView($id) { $model2 = $this->findModel($id); $model = new Kehadiran(); if (!empty($_POST)) { $count = count($_POST['hitung']); for ($i = 1; $i <= $count; $i++) { $model = new Kehadiran(); if (!empty($_POST)) { $model->user_id = $_POST['Kehadiran']['user_id'][$i]; $model->status = $_POST['Kehadiran']['status'][$i]; $model->keterangan = $_POST['Kehadiran']['keterangan'][$i]; $model->tanggal = date('Y-m-d H:i:s'); $model->mentor_id = $model2->id; $model->save(); } } return $this->redirect(['view', 'id' => $model->kehadiran_id]); } else { return $this->render('view', ['model' => $model, 'model2' => $model2]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Kehadiran::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(['kehadiran_id' => $this->kehadiran_id, 'user_id' => $this->user_id, 'tanggal' => $this->tanggal, 'status' => $this->status]); $query->andFilterWhere(['like', 'keterangan', $this->keterangan]); return $dataProvider; }
use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $searchModel common\models\KehadiranSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Kehadirans'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="kehadiran-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Kehadiran', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'anggota.nim', 'anggota.full_name', 'anggota.prodi', 'tanggal', ['attribute' => 'Status Hadir', 'value' => function ($data) { return \common\models\Kehadiran::Status($data->status); }], 'keterangan', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
/** * Finds the Kehadiran model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Kehadiran the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Kehadiran::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }