Example #1
0
 /**
  * Creates a new Page model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Page();
     if ($model->load(Yii::$app->request->post())) {
         $model->url = UrlHelp::translateUrl($model->name);
         if ($model->validate()) {
             $model->imageFile = UploadedFile::getInstance($model, 'imageFile');
             if ($model->imageFile) {
                 if ($imgName = $model->upload($model->url)) {
                     $model->img = $imgName;
                 }
             }
             $model->imageFile = null;
             $model->save();
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Example #2
0
 public function autoCreatePage($serialized_params = null, $saveIt = true)
 {
     $page = new Page();
     $page->scenario = 'autoCreate';
     if ($serialized_params != null) {
         $page->params = $serialized_params;
     }
     // validate to set values from validation default
     if (!$page->validate()) {
         var_dump($page->errors);
         die;
     }
     // save if asked
     if ($saveIt && !$page->save()) {
         var_dump($page->errors);
     }
     return $page;
 }