예제 #1
0
 /**
  * Creates a new StuDocs model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new StuDocs();
     if ($model->load(Yii::$app->request->post())) {
         $model->attributes = $_POST['StuDocs'];
         $model->created_by = Yii::$app->getid->getId();
         $model->stu_docs_stu_master_id = 3;
         $model->stu_docs_submited_at = new \yii\db\Expression('NOW()');
         $model->stu_docs_path = UploadedFile::getInstance($model, 'stu_docs_path');
         $model->stu_docs_path->saveAs(Yii::$app->basePath . '/web/data/stu_docs/' . $model->stu_docs_path);
         if ($model->save(false)) {
             return $this->redirect(['view', 'id' => $model->stu_docs_id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #2
0
 public function actionAdddocs()
 {
     $stu_docs = new StuDocs();
     if ($stu_docs->load(Yii::$app->request->post())) {
         $stu_docs->attributes = $_POST['StuDocs'];
         if (!empty($_REQUEST['StuDocs']['stu_docs_path'])) {
             $newFName = '';
             foreach ($_REQUEST['StuDocs']['stu_docs_path'] as $k => $v) {
                 $stu_docs->stu_docs_id = NULL;
                 $stu_docs->isNewRecord = true;
                 $stu_docs->stu_docs_path = UploadedFile::getInstance($stu_docs, 'stu_docs_path[' . $k . ']');
                 if (!empty($stu_docs->stu_docs_path)) {
                     $ext = substr(strrchr($stu_docs->stu_docs_path, '.'), 1);
                     if ($ext != null) {
                         $newFName = $_REQUEST['StuDocs']['stu_docs_stu_master_id'] . '-' . $k . '-' . mt_rand(1, time()) . '.' . $ext;
                         $stu_docs->stu_docs_path->saveAs(Yii::getAlias('@webroot') . '/data/stu_docs/' . ($stu_docs->stu_docs_path = $newFName));
                     }
                     $stu_docs->stu_docs_details = $_REQUEST['StuDocs']['stu_docs_details'][$k];
                     $stu_docs->stu_docs_category_id = $_REQUEST['StuDocs']['stu_docs_category_id'][$k];
                     $stu_docs->stu_docs_stu_master_id = $_REQUEST['StuDocs']['stu_docs_stu_master_id'];
                     $stu_docs->created_by = Yii::$app->getid->getId();
                     $stu_docs->stu_docs_submited_at = new \yii\db\Expression('NOW()');
                     $stu_docs->save(false);
                 }
                 /*else  {
                 			if(count($stu_docs->stu_docs_path) == 0)
                 				\Yii::$app->session->setFlash('file_upload_err', 'Upload or Select atleast one File');
                 			else
                 				continue;
                 		} */
             }
         }
         return $this->redirect(['view', 'id' => $stu_docs->stu_docs_stu_master_id, '#' => 'documents']);
     }
 }