| Current Path : /var/www/html/school/backend/controllers/ |
| Current File : /var/www/html/school/backend/controllers/LoginSkinController.php |
<?php
namespace backend\controllers;
use Yii;
use backend\models\LoginSkin;
use backend\models\LoginSkinSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use kartik\file\FileInput;
use yii\web\UploadedFile;
use yii\filters\AccessControl;
use common\components\AccessRule;
/**
* LoginSkinController implements the CRUD actions for LoginSkin model.
*/
class LoginSkinController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'ruleConfig' => [
'class' => AccessRule::className(),
],
'rules' => [
[
'actions' => ['index', 'create', 'update', 'view', 'delete','set'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all LoginSkin models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new LoginSkinSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single LoginSkin model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new LoginSkin model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new LoginSkin();
if ($model->load(Yii::$app->request->post()) ) {
$model->login_skin_logo = UploadedFile::getInstances($model, 'login_skin_logo');
$model->login_skin_bgcolor = UploadedFile::getInstances($model, 'login_skin_bgcolor');
foreach ($model->login_skin_logo as $key => $file) {
$file->saveAs( 'images/' . $file->baseName . '.' . $file->extension);//Upload files to server
$model->login_skin_logo = $file->baseName . '.' . $file->extension;//Save file names in database- '**' is for separating images
}
foreach ($model->login_skin_bgcolor as $key => $file1) {
$file1->saveAs( 'images/' . $file1->baseName . '.' . $file1->extension);//Upload files to server
$model->login_skin_bgcolor = $file1->baseName . '.' . $file1->extension;//Save file names in database- '**' is for separating images
}
if(empty($model->login_skin_logo))
{
$model->login_skin_logo = Yii::$app->request->post()['hidden_logo'];
}
if(empty($model->login_skin_bgcolor))
{
$model->login_skin_bgcolor = Yii::$app->request->post()['hidden_background'];
}
$model->save(false);
return $this->redirect(['view', 'id' => $model->login_skin_id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing LoginSkin model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post())) {
$model->login_skin_logo = UploadedFile::getInstances($model, 'login_skin_logo');
$model->login_skin_bgcolor = UploadedFile::getInstances($model, 'login_skin_bgcolor');
foreach ($model->login_skin_logo as $key => $file) {
$file->saveAs( 'images/' . $file->baseName . '.' . $file->extension);//Upload files to server
$model->login_skin_logo = $file->baseName . '.' . $file->extension;//Save file names in database- '**' is for separating images
}
foreach ($model->login_skin_bgcolor as $key => $file1) {
$file1->saveAs( 'images/' . $file1->baseName . '.' . $file1->extension);//Upload files to server
$model->login_skin_bgcolor = $file1->baseName . '.' . $file1->extension;//Save file names in database- '**' is for separating images
}
if(empty($model->login_skin_logo))
{
$model->login_skin_logo = Yii::$app->request->post()['hidden_logo'];
}
if(empty($model->login_skin_bgcolor))
{
$model->login_skin_bgcolor = Yii::$app->request->post()['hidden_background'];
}
$model->save(false);
return $this->redirect(['view', 'id' => $model->login_skin_id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing LoginSkin model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
public function actionSet($id,$status)
{
$updateStatus = Yii::$app->db->createCommand()->update('dmg_login_skin',['status'=>0])->execute();
$model = LoginSkin::find()->where(['login_skin_id' => $id])->one();
//$model = $this->findModel($id);
$getS=Yii::$app->request->get('status');
$model->status = $getS;
$model->save();
//print_r($model->layout_skin_id);
return $this->redirect(['index']);
}
/**
* Finds the LoginSkin model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return LoginSkin the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = LoginSkin::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}