public function actionEdit($id) { $model = Company::findOne($id); if ($model) { throw new NotFoundHttpException(); } return $this->showForm($this->updateWithPostRequest($model)); }
public function actionUpdate($id = 0) { // $out = ['status' => 'err', 'error' => 'Unknown error']; if (\Yii::$app->user->isGuest) { throw new NotFoundHttpException(); } $r = new Request(); if ($r->post('Company')['id']) { $id = $r->post('Company')['id']; } // vd($r->post('Company')); $userID = \Yii::$app->user->getId(); if ($id) { $company = Company::findOne(['id' => $id, 'user_id' => $userID]); } else { $company = new Company(); // \Yii::$app->session->setFlash('error', 'Company ID is required.'); // $this->redirect(array('view','id'=>$company)); // $this->redirect(array('index')); // return; } // vd($company); if ($company) { if ($company->load($r->post())) { $company->user_id = $userID; if ($company->validate() && $company->save()) { //vd([$r->post(),$order->attributes]); // $out = [ // 'status' => 'ok', // 'order' => $order->id, // 'user' => $order->user_id, // 'sum' => $order->price / 100, // ]; // $this->redirect(array('view','id'=>$company)); } else { // vd($company->errors); \Yii::$app->session->setFlash('error', array_values($company->errors)[0][0]); // $out['error'] = array_values($order->errors)[0][0]; //vd($order->errors); } } } else { \Yii::$app->session->setFlash('error', 'Такой компании не существует'); $this->redirect(array('index')); return; } return $this->render('update', ['company' => $company]); // \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; // return $out; /*vd(['get' => $r->getQueryParams() , 'post' => $r->post(), 'order' => $order],1); //*/ }
/** * Finds the Faq model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Faq the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Company::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }