Дипломная работа: Автоматизация управленческого учета в дошкольном образовательном учреждении (на примере ИП «Мельникова»)

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
112
{
$model = new Position();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing Position 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)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing Position model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
113
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Position model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Position the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Position::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}
<?php
namespace backend\models;
use Yii;
/**
* This is the model class for table "{{%position}}".
*
* @property int $id
* @property string $name
114
* @property string $arrangement
*
* @property Employee[] $employees
*/
class Position extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return '{{%position}}';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['name', 'arrangement'], 'required'],
[['name', 'arrangement'], 'string', 'max' => 255],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Name',
'arrangement' => 'Arrangement',
];
}
115
/**
* Gets query for [[Employees]].
*
* @return \yii\db\ActiveQuery
*/
public function getEmployees()
{
return $this->hasMany(Employee::className(), ['position_id' => 'id']);
}
}
<?php
namespace backend\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\Position;
/**
* PositionSearch represents the model behind the search form of
`backend\models\Position`.
*/
class PositionSearch extends Position
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id'], 'integer'],
[['name', 'arrangement'], 'safe'],
];
}
/**
116
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Position::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when
validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
Источник: https://baza.diplomsite.ru/previewfile/571