示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $id = ArrayHelper::getValue($params, 'id');
     if ($id > 0) {
         $query = InventoryActsTb::find()->where(['act_id' => $id]);
     } else {
         $query = InventoryActsTb::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, 'act_id' => $this->act_id, 'device_id' => $this->device_id, 'device_workplace_id' => $this->device_workplace_id]);
     $query->andFilterWhere(['like', 'status', $this->status]);
     return $dataProvider;
 }
 /**
  * Finds the InventoryActsTb model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return InventoryActsTb the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = InventoryActsTb::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Удаляем документ и его табличную часть
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     if (InventoryActsTb::deleteAll(['act_id' => $id])) {
     } else {
         Yii::$app->session->setFlash('error', 'Возникла ошибка при удалении строк документа');
     }
     if ($model->delete()) {
     } else {
         Yii::$app->session->setFlash('error', 'Возникла ошибка при удалении документа');
     }
     return $this->redirect(['index']);
 }