Example #1
0
 /**
  * View a page with statistics data
  * @param  string $id page id
  */
 public function actionPublish($id)
 {
     $pageId = new \MongoId($id);
     $page = Page::findByPk($pageId);
     if (empty($page)) {
         throw new ServerErrorHttpException(Yii::t('microSite', 'page_not_exist'));
     }
     $cpts = PageComponent::getAllComponents($pageId);
     $page->cpts = ArrayHelper::toArray($cpts);
     $page->isFinished = true;
     if ($page->validate()) {
         // all inputs are valid
         if ($page->save()) {
             return ['message' => 'ok'];
         } else {
             throw new ServerErrorHttpException(Yii::t('common', 'save_fail'));
         }
     } else {
         // valid fail, return errors
         return $page->errors;
     }
 }