user->can('validateUser')){ $this->goHome(); } if (! Yii::$app->user->isGuest ) { if (Yii::$app->session ['userSessionTimeout'] < time ()) { Yii::$app->user->logout (); $this->goHome (); Yii::$app->session->setFlash ( 'success', 'You have been logged out!' ); } else { Yii::$app->session->set ( 'userSessionTimeout', time () + Yii::$app->params ['sessionTimeoutSeconds'] ); return true; } } else { return true; } return true; // or false to not run the action } public function behaviors() { return [ 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['post'], ], ], ]; } /** * Lists all Carousel models. * @return mixed */ public function actionIndex() { $searchModel = new CarouselSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } /** * Changes sequence of carousel item. * @return mixed */ public function actionMove($id, $d) { $searchModel = new CarouselSearch(); $Carousel = Carousel::findOne($id); $item = (int) $_GET['id']; // = id $sequence = (int) $Carousel->sequence; // = sequence $update_item = false; if ($_GET['d'] == 'u') { $update_item = '+'; $update_other = '-'; $sort_other = $sequence + 1; } elseif ($_GET['d'] == 'd') { $update_item= '-'; $update_other = '+'; $sort_other = $sequence - 1; } if ($update_item) { $Other = Carousel::findOne($sort_other); if($update_other == '-') $NewSequenceOther = $Other->sequence - 1; else $NewSequenceOther = $Other->sequence +1; $OtherItem = (int) $Other->carouselid; $Other->updateAttributes(['sequence' => $NewSequenceOther], 'carouselid = '.$OtherItem); $Carousel->updateAttributes(['sequence' => $sort_other], 'carouselid = '.$item); } return $this->redirect('index'); } /** * Displays a single Carousel model. * @param string $id * @return mixed */ public function actionView($id) { return $this->render('view', [ 'model' => $this->findModel($id), ]); } /** * Creates a new Carousel model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Carousel(); if ($model->load(Yii::$app->request->post()) ) { // $image = 'c:/xampp/htdocs/portals/portal/ggbnsandbox/web/images/slider/' . $model->imageurl; // $model->image = $image; if($model->save()) { $model->imageurl = UploadedFile::getInstance($model, 'imageurl'); if ($model->upload()) { // file is uploaded successfully return $this->redirect('index'); } } } else { return $this->render('create', [ 'model' => $model, ]); } } /** * Updates an existing Carousel model. * If update is successful, the browser will be redirected to the 'view' page. * @param string $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { // return $this->redirect(['view', 'id' => $model->carouselid]); return $this->redirect('../index'); } else { return $this->render('update', [ 'model' => $model, ]); } } /** * Deletes an existing Carousel model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param string $id * @return mixed */ public function actionDelete($id) { $this->findModel($id)->delete(); return $this->redirect(['index']); } /** * Finds the Carousel model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Carousel the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Carousel::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } }