public function actionAjaxCreate()
 {
     $model = new Fine();
     $json = [];
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $json['result'] = 'success';
         $json['id'] = $model->id;
     } else {
         $json['result'] = 'fail';
         $json['errors'] = current($model->getFirstErrors());
     }
     return json_encode($json);
 }
Beispiel #2
0
 public function search($params)
 {
     $query = Fine::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false, 'sort' => new \yii\data\Sort(['attributes' => ['id', 'sum', 'created_at'], 'defaultOrder' => ['created_at' => SORT_DESC]])]);
     $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, 'staffer_id' => $this->staffer_id]);
     $query->andFilterWhere(['like', 'reason', $this->reason]);
     $query->andFilterWhere(['like', 'comment', $this->comment]);
     $query->andFilterWhere(['like', 'created_at', $this->created_at]);
     return $dataProvider;
 }
Beispiel #3
0
 public function getFines($where = false)
 {
     return $this->hasMany(Fine::className(), ['staffer_id' => 'id']);
 }