banki.test/controllers/ListController.php

63 lines
1.4 KiB
PHP

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