| Current Path : /var/www/html/sprm/backend/controllers/ |
| Current File : /var/www/html/sprm/backend/controllers/LayoutSkinController.php |
<?php
namespace backend\controllers;
use Yii;
use backend\models\LayoutSkin;
use backend\models\LayoutStatus;
use backend\models\LayoutSkinSearch;
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;
/**
* LayoutSkinController implements the CRUD actions for LayoutSkin model.
*/
class LayoutSkinController 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 LayoutSkin models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new LayoutSkinSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$modelSkin = LayoutSkin::find()->all();
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'skin' => $modelSkin,
]);
}
/**
* Displays a single LayoutSkin model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new LayoutSkin model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new LayoutSkin();
$status = 0;
if ($model->load(Yii::$app->request->post()) ) {
$model->status = $status;
$model->layout_skin_logo = UploadedFile::getInstances($model, 'layout_skin_logo');
// echo '<pre>'; var_dump(__DIR__); echo '</pre>';die();
foreach ($model->layout_skin_logo as $key => $file) {
$file->saveAs( 'images/' . $file->baseName . '.' . $file->extension);
//Upload files to server
$model->layout_skin_logo = $file->baseName . '.' . $file->extension;//Save file names in database- '**' is for separating images;
}
if(empty($model->layout_skin_logo))
{
$model->layout_skin_logo = Yii::$app->request->post()['hidden_logo'];
}
$model->save(false);
return $this->redirect(['view', 'id' => $model->layout_skin_id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing LayoutSkin 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->layout_skin_logo = UploadedFile::getInstances($model, 'layout_skin_logo');
// print_r($model->layout_skin_logo[0]->name);
foreach ($model->layout_skin_logo as $key => $file) {
$file->saveAs( 'images/' . $file->baseName . '.' . $file->extension);
//Upload files to server
$model->layout_skin_logo = $file->baseName . '.' . $file->extension;//Save file names in database- '**' is for separating images
}
if(empty($model->layout_skin_logo))
{
$model->layout_skin_logo = Yii::$app->request->post()['hidden_logo'];
}
$model->save(false);
return $this->redirect(['view', 'id' => $model->layout_skin_id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing LayoutSkin 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_layout_skin',['status'=>0])->execute();
$model = LayoutSkin::find()->where(['layout_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 LayoutSkin model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return LayoutSkin the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = LayoutSkin::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}