public function actionReg() { $model = new \frontend\models\SignupForm(); if ($model->load(Yii::$app->request->post())) { if ($user = $model->signup()) { if (Yii::$app->getUser()->login($user)) { return $this->goHome(); } } } return $this->render('reg', ['model' => $model]); }
/** * Creates a new Siswa model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Siswa(); $nilai = new Nilai(); $post = Yii::$app->request->post(); if ($model->load($post)) { $tgllahir = strtotime($post['Siswa']['thn'] . '-' . $post['Siswa']['bln'] . '-' . $post['Siswa']['tgl']); $model->tgl_lahir = date('Y-m-d', $tgllahir); $foto = UploadedFile::getInstance($model, 'foto'); if ($foto) { $ext = end(explode(".", $foto->name)); $extt = $foto->extension; $model->foto = Yii::$app->security->generateRandomString() . "." . $extt; } if ($model->save()) { if ($foto) { mkdir('uploads/foto_siswa', 0777, true); $foto->saveAs('uploads/foto_siswa/' . $model->foto); } $signUp = new \frontend\models\SignupForm(); $signUp->username = $model->email; $signUp->email = $model->email; $signUp->password = $model->password; $signUp->level = 'Siswa'; $mapel = MatapelajaranGuru::find()->all(); foreach ($mapel as $key => $value) { $nilai->nis = $model->nis; $nilai->id_matapelajaran = $value->id_matapelajaran_guru; $nilai->tahun_ajaran = $_POST['Nilai']['tahun_ajaran']; if ($nilai->save()) { $nilai = new Nilai(); } } if ($signUp->signup()) { Yii::$app->session->setFlash('success', 'Simpan Berhasil'); } else { Yii::$app->session->setFlash('warning', 'Simpan Gagal'); } return $this->redirect(['index']); } else { Yii::$app->session->setFlash('warning', 'Failed'); } } else { return $this->render('create', ['model' => $model, 'nilai' => $nilai]); } }
/** * Creates a new Admin model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Admin(); if ($model->load(Yii::$app->request->post())) { if ($model->save()) { $signUp = new \frontend\models\SignupForm(); $signUp->username = $model->username; $signUp->email = $model->username . '@gmail.com'; $signUp->password = $model->password; $signUp->level = 'admin'; if ($signUp->signup()) { Yii::$app->session->setFlash('success', 'Simpan Berhasil'); } else { Yii::$app->session->setFlash('warning', 'Simpan gagal'); } } else { Yii::$app->session->setFlash('warning', 'Failed'); } return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Guru model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Guru(); $post = Yii::$app->request->post(); if ($model->load($post)) { $tgllahir = strtotime($post['Guru']['thn'] . '-' . $post['Guru']['bln'] . '-' . $post['Guru']['tgl']); $model->tgl_lahir = date('Y-m-d', $tgllahir); $foto = UploadedFile::getInstance($model, 'foto'); if ($foto) { $ext = end(explode(".", $foto->name)); $extt = $foto->extension; $model->foto = Yii::$app->security->generateRandomString() . "." . $extt; } if ($model->save()) { if ($foto) { $foto->saveAs('uploads/foto_guru/' . $model->foto); } $signUp = new \frontend\models\SignupForm(); $signUp->username = $model->email; $signUp->email = $model->email; $signUp->password = $model->password; $signUp->level = 'guru'; // echo '<pre>'; // print_r($signUp);die(); if ($signUp->signup()) { Yii::$app->session->setFlash('success', 'Simpan Berhasil'); } else { Yii::$app->session->setFlash('warning', 'Simpan Gagal'); } return $this->redirect(['index']); } else { Yii::$app->session->setFlash('warning', 'Failed'); } } else { return $this->render('create', ['model' => $model]); } }