/** * Creates a new Gallery model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $ajax = Yii::$app->request->post('ajax'); $model = new Gallery(); if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($ajax) { return json_encode($model->toArray()); } return $this->redirect(['view', 'id' => $model->id]); } else { if ($ajax) { return json_encode($model->getErrors()); } return $this->render('create', ['model' => $model]); } }
/** * Creates a new Gallery model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($table_id) { if (CatalogProducts::findOne($table_id)->createdby == \Yii::$app->user->getId()) { $model = new Gallery(); if ($model->load(Yii::$app->request->post())) { $model->table_id = $table_id; $model->table_name = 'catalog'; if ($model->save()) { $this->actionUpload($model); return $this->redirect(['index', 'table_id' => $table_id]); } else { return $this->render('create', ['model' => $model, 'table_id' => $table_id]); } } else { return $this->render('create', ['model' => $model, 'table_id' => $table_id]); } } else { throw new NotFoundHttpException('The requested page does not exist.'); } }