예제 #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;
 }