Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\controllers;
- use Yii;
- use app\models\Attendence;
- use app\models\AttendenceSearch;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- /**
- * AttendenceController implements the CRUD actions for Attendence model.
- */
- class AttendenceController extends Controller
- {
- /**
- * {@inheritdoc}
- */
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['POST'],
- ],
- ],
- ];
- }
- /**
- * Lists all Attendence models.
- * @return mixed
- */
- public function actionIndex()
- {
- $searchModel = new AttendenceSearch();
- $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
- return $this->render('index', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- ]);
- }
- /**
- * Displays a single Attendence model.
- * @param integer $id
- * @return mixed
- * @throws NotFoundHttpException if the model cannot be found
- */
- public function actionView()
- {
- //$request = Yii::$app->request;
- //$id = $request->post('id');
- $headers = Yii::$app->request->headers;
- $id = $headers->get('id');
- $cmd = Yii::$app->db->createCommand('SELECT * FROM attendence WHERE id = :id');
- $post = $cmd->bindParam(':id', $id)->queryOne();
- $response = Yii::$app->response;
- $response->format = \yii\web\Response::FORMAT_JSON;
- $response->data = ['data' => $post ];
- }
- public function actionView1($id)
- {
- $cmd = Yii::$app->db->createCommand('SELECT * FROM attendence WHERE id = :id');
- $post = $cmd->bindParam(':id', $id)->queryOne();
- return $this->render('post',['dataProvider' => $post]);
- }
- public function actionView2($id)
- {
- if($id == 'error1'){
- return $this->render('post',['dataProvider' => 'Error logging in:Invalid username or password' ]);
- }
- if($id == 'error2'){
- return $this->render('post',['dataProvider' => 'Error logging in:Invalid ' ]);
- }
- $cmd = Yii::$app->db->createCommand('SELECT * FROM attendence WHERE id = :id');
- $post = $cmd->bindParam(':id', $id)->queryOne();
- return $this->render('post',['dataProvider' => $post]);
- }
- /**
- * Creates a new Attendence model.
- * If creation is successful, the browser will be redirected to the 'view' page.
- * @return mixed
- */
- public function actionCreate()
- {
- $model = new Attendence();
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
- }
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- public function actionPost()
- {
- $request = Yii::$app->request;
- $username = $request->post('username');
- $password = $request->post('password');
- $error= 'error';
- if(isset($username) && isset($password)){
- $cmd = Yii::$app->db->createCommand('SELECT * FROM attendence
- WHERE username = :username AND password = :password ');
- $post = $cmd->bindParam(':username', $username)
- ->bindParam(':password', $password )
- ->queryOne();
- //emplogin.php in views
- if($post != false)
- return $this->redirect(['view2', 'id' => $post->id]);
- else
- return $this->redirect(['view2', 'id' => 'error1']);
- }
- else
- return $this->render('test');
- }
- public function actionDocument() {
- $model = new Attendence();
- if($model->load(Yii::$app->request->post())){
- if ($model->validate()) {
- // all inputs are valid
- $username = $model->username;
- $password = $model->password;
- $cmd = Yii::$app->db->createCommand('SELECT * FROM attendence
- WHERE username = :username
- AND password = :password ');
- $post = $cmd->bindParam(':username', $username)
- ->bindParam(':password', $password)
- ->queryOne();
- return $this->render('post',['dataProvider' => $username]);
- }
- else {
- // validation failed: $errors is an array containing error messages
- $errors = $model->errors;
- return $this->render('post',['dataProvider' => $errors]);
- }
- }
- return $this->render('document.php', [
- 'model' => $model,
- ]);
- }
- /**
- * Updates an existing Attendence model.
- * If update is successful, the browser will be redirected to the 'view' page.
- * @param integer $id
- * @return mixed
- * @throws NotFoundHttpException if the model cannot be found
- */
- public function actionUpdate($id)
- {
- $model = $this->findModel($id);
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
- }
- return $this->render('update', [
- 'model' => $model,
- ]);
- }
- /**
- * Deletes an existing Attendence model.
- * If deletion is successful, the browser will be redirected to the 'index' page.
- * @param integer $id
- * @return mixed
- * @throws NotFoundHttpException if the model cannot be found
- */
- public function actionDelete($id)
- {
- $this->findModel($id)->delete();
- return $this->redirect(['index']);
- }
- /**
- * Finds the Attendence model based on its primary key value.
- * If the model is not found, a 404 HTTP exception will be thrown.
- * @param integer $id
- * @return Attendence the loaded model
- * @throws NotFoundHttpException if the model cannot be found
- */
- protected function findModel($id)
- {
- if (($model = Attendence::findOne($id)) !== null) {
- return $model;
- }
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
Add Comment
Please, Sign In to add comment