| Current Path : /var/www/html/chatbot/backend/controllers/banci/ |
| Current File : /var/www/html/chatbot/backend/controllers/banci/BanciImageSliderController.php |
<?php
namespace backend\controllers\banci;
use Yii;
use backend\models\BanciImageSlider;
use backend\models\BanciImageSliderSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\UploadedFile;
use yii\filters\AccessControl;
use common\components\AccessRule;
/**
* BanciImageSliderController implements the CRUD actions for BanciImageSlider model.
*/
class BanciImageSliderController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'ruleConfig' => [
'class' => AccessRule::className(),
],
'rules' => [
[
'actions' => ['index', 'create', 'update', 'view', 'delete'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all BanciImageSlider models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new BanciImageSliderSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single BanciImageSlider model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new BanciImageSlider model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new BanciImageSlider();
$model->scenario = 'create';
if ($model->load(Yii::$app->request->post())) {
$model->banci_image_slider_image_url = UploadedFile::getInstance($model, 'banci_image_slider_image_url');
$model->banci_image_slider_image_url_en = UploadedFile::getInstance($model, 'banci_image_slider_image_url_en');
if ($model->upload()) {
// file is uploaded successfully
if ($model->save(false)) {
return $this->redirect(['index']);
}
}
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing BanciImageSlider 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);
$model->scenario = 'update';
$model->uppath = $model->banci_image_slider_image_url;
$model->uppathen = $model->banci_image_slider_image_url_en;
if ($model->load(Yii::$app->request->post())) {
$model->banci_image_slider_image_url = UploadedFile::getInstance($model, 'banci_image_slider_image_url');
$model->banci_image_slider_image_url_en = UploadedFile::getInstance($model, 'banci_image_slider_image_url_en');
if ($model->upload()) {
// file is uploaded successfully
if ($model->save(false)) {
return $this->redirect(['index']);
}
}
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing BanciImageSlider 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)
{
$model = $this->findModel($id);
$url = $model->banci_image_slider_image_url;
$url = Yii::getAlias('@webroot') . "/uploads/" . $url;
if(file_exists($url)){
unlink($url);
}
$model->delete();
return $this->redirect(['index']);
}
/**
* Finds the BanciImageSlider model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return BanciImageSlider the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = BanciImageSlider::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
}
}