Ejemplo n.º 1
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)]);
 }