banki.test/controllers/ListController.php

65 lines
1.5 KiB
PHP

<?php
namespace app\controllers;
use app\models\Parameter;
use app\models\ParameterForm;
use app\models\ParameterSearch;
use yii\data\ActiveDataProvider;
use yii\web\NotFoundHttpException;
use yii\web\Request;
use yii\web\UploadedFile;
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,
]
);
}
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,
]
);
}
}