| Current Path : /var/www/html/mycoastv2/backend/modules/data/controllers/ |
| Current File : /var/www/html/mycoastv2/backend/modules/data/controllers/DataDataController.php |
<?php
namespace backend\modules\data\controllers;
use Yii;
use backend\modules\data\models\DataData;
use backend\modules\data\models\DataDataSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* DataDataController implements the CRUD actions for DataData model.
*/
class DataDataController extends Controller {
/**
* {@inheritdoc}
*/
public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all DataData models.
* @return mixed
*/
public function actionIndex($listmetadata = '') {
$searchModel = new DataDataSearch();
if (!empty($listmetadata))
$searchModel->data_metadata_id = $listmetadata;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'listmetadata' => $listmetadata]);
}
/**
* Displays a single DataData model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id, $listmetadata = '') {
return $this->render('view', ['model' => $this->findModel($id), 'listmetadata' => $listmetadata]);
}
/**
* Creates a new DataData model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate($listmetadata = '') {
$model = new DataData();
if (!empty($listmetadata))
$model->data_metadata_id = $listmetadata;
$model->created_at = date("Y-m-d H:i:s");
$model->created_by = Yii::$app->user->identity->id;
$model->updated_at = date("Y-m-d H:i:s");
$model->updated_by = Yii::$app->user->identity->id;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index', 'listmetadata' => $listmetadata]);
}
return $this->render('create', ['model' => $model, 'listmetadata' => $listmetadata]);
}
/**
* Updates an existing DataData 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, $listmetadata = '') {
$model = $this->findModel($id);
$model->updated_at = date("Y-m-d H:i:s");
$model->updated_by = Yii::$app->user->identity->id;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index', 'listmetadata' => $listmetadata]);
}
return $this->render('update', ['model' => $model, 'listmetadata' => $listmetadata]);
}
/**
* Deletes an existing DataData 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, $listmetadata = '') {
$this->findModel($id)->delete();
return $this->redirect(['index', 'listmetadata' => $listmetadata]);
}
/**
* Finds the DataData model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return DataData the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id) {
if (($model = DataData::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
}
}