/** * Creates a new Exam model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Exam(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Exam model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Exam(); if ($model->load(Yii::$app->request->post())) { $model->addtime = time(); if (Yii::$app->request->isPost) { $model->files = UploadedFile::getInstance($model, 'file_excel'); if ($file_path = $model->upload()) { $model->file_excel = $file_path; } $model->files = UploadedFile::getInstance($model, 'head_logo'); if ($logo_path = $model->upload()) { $model->head_logo = $logo_path; } } $model->save(false); //试题入库 $count = $model->excel_insert($file_path, (string) $model->_id); $model->q_count = $count; $model->save(false); return $this->redirect(['view', 'id' => (string) $model->_id]); } else { //查询职业方向 $job = Category::find()->where(['cate_type' => '1'])->all(); $job_info = array(); foreach ($job as $val) { $job_info["{$val->_id}"] = $val->cate_name; } //查询知识 $zhishi = Category::find()->where(['cate_type' => '3'])->andWhere(['level' => '2'])->all(); $zhishi_info = array(); foreach ($zhishi as $val) { $zhishi_info["{$val->_id}"] = $val->cate_name; } //查询公司 $company = Category::find()->where(['cate_type' => '2'])->all(); $company_info = array(); foreach ($company as $val) { $company_info["{$val->_id}"] = $val->cate_name; } return $this->render('create', ['model' => $model, 'job_info' => $job_info, 'zhishi_info' => $zhishi_info, 'company_info' => $company_info]); } }