Beispiel #1
0
 public function actionCreate()
 {
     $model = new Post();
     $model->siteId = Yii::$app->cmgCore->siteId;
     $content = new ModelContent();
     $banner = CmgFile::loadFile(null, 'File');
     $model->setScenario('create');
     if ($model->load(Yii::$app->request->post(), 'Post') && $content->load(Yii::$app->request->post(), 'ModelContent') && $model->validate() && $content->validate()) {
         $post = PostService::create($model);
         if (isset($post)) {
             // Create Content
             ModelContentService::create($post, CmsGlobal::TYPE_POST, $content, $post->isPublished(), $banner);
             // Bind Categories
             $binder = new Binder();
             $binder->binderId = $model->id;
             $binder->load(Yii::$app->request->post(), 'Binder');
             PostService::bindCategories($binder);
             $this->redirect(['all']);
         }
     }
     $categories = CategoryService::getIdNameListByType(CmsGlobal::TYPE_POST);
     $visibilityMap = Page::$visibilityMap;
     $statusMap = Page::$statusMap;
     $templatesMap = TemplateService::getIdNameMapByType(CmsGlobal::TYPE_POST);
     $templatesMap = ArrayHelper::merge(['0' => 'Choose Template'], $templatesMap);
     return $this->render('create', ['model' => $model, 'content' => $content, 'banner' => $banner, 'categories' => $categories, 'visibilityMap' => $visibilityMap, 'statusMap' => $statusMap, 'templatesMap' => $templatesMap]);
 }