Ejemplo n.º 1
0
 /**
  * 调查表单提交 
  */
 public function surveysub()
 {
     if ($this->validate()) {
         $survey = new Survey();
         //save错误源:以前是 new SurveyForm()
         //$survey->attributes = $_POST['SurveyForm'];
         $survey->create_time = date('Y-m-d H:i:s', time());
         $survey->name = $_POST['SurveyForm']['name'];
         $survey->age = $_POST['SurveyForm']['age'];
         $survey->sex = $_POST['SurveyForm']['sex'];
         $survey->edu = $_POST['SurveyForm']['edu'];
         $survey->info = $_POST['SurveyForm']['info'];
         $survey->hobby = implode('/', $_POST['SurveyForm']['hobby']);
         if ($survey->hasErrors()) {
             Yii::$app->session->setFlash('haserror', '数据有问题 :(');
         }
         if ($survey->save()) {
             return $survey;
         }
     }
     return null;
 }
Ejemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Survey::find();
     $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'age' => $this->age, 'create_time' => $this->create_time]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'sex', $this->sex])->andFilterWhere(['like', 'edu', $this->edu])->andFilterWhere(['like', 'info', $this->info]);
     return $dataProvider;
 }
Ejemplo n.º 3
0
 /**
  * Finds the Survey model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Survey the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Survey::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }