| Current Path : /var/www/html/affiliate/backend/controllers/frontend/ |
| Current File : /var/www/html/affiliate/backend/controllers/frontend/FrontendContentTemplateController.php |
<?php
namespace backend\controllers\frontend;
use Yii;
use backend\models\frontendcontenttemplate\FrontendContentTemplate;
use backend\models\frontendcontenttemplate\FrontendContentTemplateSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\UploadedFile;
/**
* FrontendContentTemplateController implements the CRUD actions for FrontendContentTemplate model.
*/
class FrontendContentTemplateController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all FrontendContentTemplate models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new FrontendContentTemplateSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single FrontendContentTemplate 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 FrontendContentTemplate model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new FrontendContentTemplate();
if ( $model->load(Yii::$app->request->post()) ) {
$model->uploadImage = UploadedFile::getInstance($model, 'uploadImage');
if( $model->upload() ){
$model->save();
}
return $this->redirect(['update', 'id' => $model->frontend_content_template_id]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing FrontendContentTemplate 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->uploadImage = UploadedFile::getInstance($model, 'uploadImage');
if( !empty($model->uploadImage) )
if($model->upload()){
$model->save();
}
else
$model->save();
return $this->redirect(['index']);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing FrontendContentTemplate 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 FrontendContentTemplate model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return FrontendContentTemplate the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = FrontendContentTemplate::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
}
/**
* preview function
*
* @return void
*/
public function actionPreview($cid = null){
$this->layout = false;
$html = '';
if( !empty($cid) ){
$model = $this->findModel($cid);
$html = $model->template_html;
}
return $this->render('preview', [
'html' => $html,
]);
}
/**
* Ajax save for updated view
*
* @return void
*/
public function actionUpdateView($id){
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$data['result'] = "Success";
}else{
$data['result'] = "Failed";
}
header('Content-Type: application/json');
echo json_encode($data);
}
/**
* Snippet html creation
*
* @return void
*/
public function actionContentSnippet(){
$this->layout = false;
$model = FrontendContentTemplate::find()->all();
return $this->render('snippet', [
'model' => $model,
]);
}
}