2024-08-20 06:27:17 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\controllers;
|
|
|
|
|
|
|
|
use app\models\Parameter;
|
2024-08-20 07:53:49 +02:00
|
|
|
use app\models\ParameterForm;
|
2024-08-20 06:27:17 +02:00
|
|
|
use app\models\ParameterSearch;
|
|
|
|
|
2024-08-20 07:53:49 +02:00
|
|
|
use yii\web\NotFoundHttpException;
|
2024-08-20 06:27:17 +02:00
|
|
|
use yii\web\Request;
|
|
|
|
|
|
|
|
class ListController extends \yii\web\Controller
|
|
|
|
{
|
|
|
|
public function actionIndex(Request $request)
|
|
|
|
{
|
|
|
|
$searchModel = new ParameterSearch();
|
|
|
|
$dataProvider = $searchModel->search($request->queryParams);
|
|
|
|
|
|
|
|
return $this->render(
|
|
|
|
'index',
|
|
|
|
[
|
|
|
|
'provider' => $dataProvider,
|
|
|
|
'searchModel' => $searchModel,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-08-20 07:53:49 +02:00
|
|
|
public function actionEdit(Request $request)
|
|
|
|
{
|
|
|
|
$id = $request->getQueryParam('id');
|
|
|
|
|
|
|
|
$parameter = Parameter::findOne($id);
|
|
|
|
if ($id !== null && $parameter !== null) {
|
|
|
|
throw new NotFoundHttpException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$model = new ParameterForm();
|
|
|
|
|
|
|
|
if ($request->isPost) {
|
|
|
|
$data = $request->post();
|
|
|
|
$model->load($data);
|
|
|
|
|
|
|
|
if ($model->validate()) {
|
|
|
|
if ($id) {
|
|
|
|
$model->edit($parameter);
|
|
|
|
} else {
|
|
|
|
$id = $model->create();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->redirect('/list?ParameterSearch[id]=' . $id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render(
|
|
|
|
'edit',
|
|
|
|
[
|
|
|
|
'id' => $id,
|
|
|
|
'model' => $model,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
2024-08-20 06:27:17 +02:00
|
|
|
}
|