/** * Creates a new Warehouse model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Warehouse(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Warehouse model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (Yii::$app->user->isGuest || Yii::$app->user->identity->user_role != 4 && Yii::$app->user->identity->user_role != 3 && Yii::$app->user->identity->user_role != 2) { return $this->goHome(); } $model = new Warehouse(['scenario' => Warehouse::SCENARIO_CREATE]); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->warehouse_id]); } else { return $this->render('create', ['model' => $model]); } }
private function createAjax() { $data = Yii::$app->request->post(); $model = new Warehouse(['scenario' => Warehouse::SCENARIO_CREATE]); foreach ($data['Warehouse'] as $key => $value) { $model->{$key} = $value; } if ($model->validate()) { return $model->save() ? true : ErrorHelper::errorsToString($model->errors); } else { return ErrorHelper::errorsToString($model->errors); } }
public function upload() { if ($this->validate()) { $this->xmlFile->saveAs('uploads/' . $this->xmlFile->baseName . '.' . $this->xmlFile->extension); $xml = simplexml_load_file('uploads/' . $this->xmlFile->baseName . '.' . $this->xmlFile->extension); foreach ($xml->product as $product) { $warehouse = new Warehouse(); $warehouse->warehouse_id = null; $restaurant = Restaurant::find()->where(['name' => $product->restaurant_name])->one(); $products = Product::find()->where(['name' => $product->product_name])->one(); if (isset($products) && isset($restaurant)) { $warehouse->restaurant_id = $restaurant->restaurant_id; $warehouse->product_id = $products->product_id; $warehouse->description = $product->description; $warehouse->price = $product->price; $warehouse->save(); } } unlink('uploads/' . $this->xmlFile->baseName . '.' . $this->xmlFile->extension); return true; } else { return false; } }
public function actionCreate() { $role = UserRoleDetector::getUserRole(); Yii::$app->response->format = Response::FORMAT_JSON; if ($role != 3 && $role != 4) { echo json_encode(array('status' => 0, 'error_code' => Codes::$UNAUTHORIZED, 'errors' => StatusCodeMessage::$UNAUTHORIZED), JSON_PRETTY_PRINT); } else { $params = $_REQUEST; $model = new Warehouse(); $model->attributes = $params; if ($model->save()) { echo json_encode(array('status' => 1, 'data' => array_filter($model->attributes)), JSON_PRETTY_PRINT); } else { echo json_encode(array('status' => 0, 'error_code' => Codes::$BAD_REQUEST, 'errors' => $model->errors), JSON_PRETTY_PRINT); } } }