Ejemplo n.º 1
0
 public function actionCreate()
 {
     $model = new Document();
     if ($model->load(Yii::$app->request->post())) {
         //$model->file = UploadedFile::getInstance($model, 'documentImage');
         $model->file = UploadedFile::getInstance($model, 'file');
         $save_file = '';
         if ($model->file) {
             $imagepath = 'uploads/images/';
             // Create folder under web/uploads/logo
             $model->documentImage = $imagepath . rand(10, 100) . '-' . $model->file->name;
             $save_file = 1;
         }
         $userid = ArrayHelper::getValue(User::find()->where(['username' => Yii::$app->user->identity->username])->one(), 'id');
         $model->user_id = $userid;
         if ($model->save()) {
             //if ($model->documentImage)
             //{
             //  $model->file->saveAs($model->documentImage);
             //}
             if ($save_file) {
                 $model->file->saveAs($model->documentImage);
             }
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->renderAjax('create', ['model' => $model]);
     }
 }
Ejemplo n.º 2
0
 /**
  * Создание нового документа
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Document();
     $model->parent_id = Yii::$app->request->get('parent_id');
     $model->status = Document::STATUS_ACTIVE;
     if ($model->load(Yii::$app->request->post())) {
         $model->injectValidate();
         $model = $this->loadAttributes($model);
         if ($model->validate()) {
             // Получаем будущего родителя
             $node = $this->findModel($model->parent_id);
             if ($model->appendTo($node)->save()) {
                 $model->savePhoto();
             }
             Yii::$app->getSession()->setFlash('document-create-success');
             return $this->redirect(['update', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model, 'template' => Template::findOne($model->template_id)]);
 }