/** * Finds the Depart model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Depart the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Depart::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Updates an existing Userdata model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'depart' => Depart::find()->all()]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Depart::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->pagination->pageSize = 10; $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; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name_depart', $this->name_depart]); return $dataProvider; }
use app\models\Depart; /* @var $this yii\web\View */ /* @var $searchModel app\models\UserDataSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ ?> <div class="user-data-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Добавить данные сотрудника', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'id_depart', 'filter' => ArrayHelper::map(Depart::find()->orderBy('name_depart')->asArray()->all(), 'id', 'name_depart'), 'label' => 'Департамент', 'value' => function ($data) { return $data->idDepart->name_depart; }], 'pib', 'position', 'pasport', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
/** * @return \yii\db\ActiveQuery */ public function getIdDepart() { return $this->hasOne(Depart::className(), ['id' => 'id_depart']); }
<?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Добавить командировку', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php $gridColumns = [['class' => 'yii\\grid\\ActionColumn'], ['attribute' => 'numbertrip', 'label' => '№ Командировки'], ['attribute' => 'iduserdata', 'filter' => ArrayHelper::map(\app\models\Userdata::find()->orderBy('pib')->asArray()->all(), 'id', 'pib'), 'label' => 'Фамилия Имя Отчество', 'value' => function ($data) { return $data->userdata1->pib; }], ['attribute' => 'depart', 'filter' => ArrayHelper::map(\app\models\Depart::find()->orderBy('name_depart')->asArray()->all(), 'id', 'name_depart'), 'value' => function ($data) { return $data->userdata1->idDepart->name_depart; }], ['attribute' => 'test', 'value' => function ($data) { return $data->client1->directions->sity; }], ['attribute' => 'idclient', 'label' => 'Предприятие для командировки ', 'headerOptions' => ['width' => '380'], 'filter' => ArrayHelper::map(\app\models\Client::find()->orderBy('nameclient')->asArray()->all(), 'id', 'nameclient'), 'width' => '150px', 'value' => function ($data) { return $data->client1->nameclient; }], ['attribute' => 'idproject', 'label' => 'Проект/Клиент для командировки', 'filter' => ArrayHelper::map(\app\models\Project::find()->orderBy('name_project')->asArray()->all(), 'id', 'name_project'), 'value' => function ($data) { return $data->project1->name_project; }], ['attribute' => 'date_otpr', 'label' => 'Дата отправления', 'format' => 'datetime'], ['attribute' => 'date_pr', 'label' => 'Дата прибытия.', 'format' => 'datetime'], ['attribute' => 'date_otpr1', 'label' => 'Дата отправления', 'format' => 'datetime'], ['attribute' => 'date_pr1', 'label' => 'Дата прибытия.', 'format' => 'datetime'], ['label' => 'Количество дней', 'value' => function ($data) { $datetime1 = new DateTime(date('Y-m-d', $data->date_otpr)); $datetime2 = new DateTime(date('Y-m-d', $data->date_pr1)); $interval = $datetime1->diff($datetime2); $interval = $interval->format('%R%a'); $interval = $interval + 1; return $interval; }], ['attribute' => 'daily', 'format' => ['decimal', 2]], ['label' => 'Командировочные', 'format' => ['decimal', 2], 'value' => function ($data) {