mirror of
https://github.com/CyanoFresh/SmartHomePHP.git
synced 2026-02-20 19:31:20 +01:00
86 lines
2.1 KiB
PHP
86 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace app\controllers;
|
|
|
|
use Yii;
|
|
use app\models\History;
|
|
use app\models\HistorySearch;
|
|
use yii\filters\AccessControl;
|
|
use yii\web\Controller;
|
|
use yii\web\NotFoundHttpException;
|
|
use yii\filters\VerbFilter;
|
|
|
|
/**
|
|
* HistoryController implements the CRUD actions for History model.
|
|
*/
|
|
class HistoryController extends Controller
|
|
{
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function behaviors()
|
|
{
|
|
return [
|
|
'verbs' => [
|
|
'class' => VerbFilter::className(),
|
|
'actions' => [
|
|
'delete' => ['POST'],
|
|
],
|
|
],
|
|
'access' => [
|
|
'class' => AccessControl::className(),
|
|
'rules' => [
|
|
[
|
|
'allow' => true,
|
|
'roles' => ['@'],
|
|
],
|
|
],
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Lists all History models.
|
|
* @return mixed
|
|
*/
|
|
public function actionIndex()
|
|
{
|
|
$searchModel = new HistorySearch();
|
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
|
|
|
return $this->render('index', [
|
|
'searchModel' => $searchModel,
|
|
'dataProvider' => $dataProvider,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Deletes an existing History 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']);
|
|
}
|
|
|
|
/**
|
|
* Finds the History model based on its primary key value.
|
|
* If the model is not found, a 404 HTTP exception will be thrown.
|
|
* @param integer $id
|
|
* @return History the loaded model
|
|
* @throws NotFoundHttpException if the model cannot be found
|
|
*/
|
|
protected function findModel($id)
|
|
{
|
|
if (($model = History::findOne($id)) !== null) {
|
|
return $model;
|
|
} else {
|
|
throw new NotFoundHttpException('The requested page does not exist.');
|
|
}
|
|
}
|
|
}
|