Advertisement
pmtpenza

Untitled

Jun 25th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. <?php
  2.  
  3. namespace backend\controllers;
  4.  
  5. use Yii;
  6. use backend\models\Zayvki;
  7. use backend\models\ZayvkiSearch;
  8. use yii\web\Controller;
  9. use yii\web\NotFoundHttpException;
  10. use yii\filters\VerbFilter;
  11. use backend\models\Order;
  12. use backend\models\OrderForm;
  13.  
  14. /**
  15. * ZayvkiController implements the CRUD actions for Zayvki model.
  16. */
  17. class ZayvkiController extends Controller
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function behaviors()
  23. {
  24. return [
  25. 'verbs' => [
  26. 'class' => VerbFilter::className(),
  27. 'actions' => [
  28. 'delete' => ['POST'],
  29. ],
  30. ],
  31. ];
  32. }
  33.  
  34. /**
  35. * Lists all Zayvki models.
  36. * @return mixed
  37. */
  38. public function actionIndex()
  39. {
  40. $searchModel = new ZayvkiSearch();
  41. $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  42.  
  43. return $this->render('index', [
  44. 'searchModel' => $searchModel,
  45. 'dataProvider' => $dataProvider,
  46. ]);
  47. }
  48.  
  49. /**
  50. * Displays a single Zayvki model.
  51. * @param integer $id
  52. * @return mixed
  53. * @throws NotFoundHttpException if the model cannot be found
  54. */
  55. public function actionView($id)
  56. {
  57. return $this->render('view', [
  58. 'model' => $this->findModel($id),
  59. ]);
  60. }
  61.  
  62. /**
  63. * Creates a new Zayvki model.
  64. * If creation is successful, the browser will be redirected to the 'view' page.
  65. * @return mixed
  66. */
  67. public function actionCreate()
  68. {
  69. $model = new Zayvki();
  70.  
  71. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  72. $order = new Order();
  73. $order->load(Yii::$app->request->post());
  74. $order->uslugi_id = Yii::$app->request->post('Zayvki')['uslugi_id'];
  75. $order->hours = Yii::$app->request->post('Zayvki')['hours'];
  76. $order->date = Yii::$app->request->post('Zayvki')['date'];
  77. $order->category_id = 3;
  78. $order->link('zayvki', $model);
  79. return $this->redirect(['view', 'id' => $model->id]);
  80. }
  81.  
  82.  
  83. return $this->render('create', [
  84. 'model' => $model,
  85. ]);
  86. }
  87.  
  88. public function actionCreateiko()
  89. {
  90. $model = new Zayvki();
  91. $orders = [new OrderForm()];
  92. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  93.  
  94. return $this->redirect(['view', 'id' => $model->id]);
  95. }
  96. return $this->render('createiko', [
  97. 'model' => $model,
  98. 'orders' => $order,
  99. ]);
  100. }
  101.  
  102. /**
  103. * Updates an existing Zayvki model.
  104. * If update is successful, the browser will be redirected to the 'view' page.
  105. * @param integer $id
  106. * @return mixed
  107. * @throws NotFoundHttpException if the model cannot be found
  108. */
  109. public function actionUpdate($id)
  110. {
  111. $model = $this->findModel($id);
  112.  
  113. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  114. return $this->redirect(['view', 'id' => $model->id]);
  115. }
  116.  
  117. return $this->render('update', [
  118. 'model' => $model,
  119. ]);
  120. }
  121.  
  122. /**
  123. * Deletes an existing Zayvki model.
  124. * If deletion is successful, the browser will be redirected to the 'index' page.
  125. * @param integer $id
  126. * @return mixed
  127. * @throws NotFoundHttpException if the model cannot be found
  128. */
  129. public function actionDelete($id)
  130. {
  131. $this->findModel($id)->delete();
  132.  
  133. return $this->redirect(['index']);
  134. }
  135.  
  136. /**
  137. * Finds the Zayvki model based on its primary key value.
  138. * If the model is not found, a 404 HTTP exception will be thrown.
  139. * @param integer $id
  140. * @return Zayvki the loaded model
  141. * @throws NotFoundHttpException if the model cannot be found
  142. */
  143. protected function findModel($id)
  144. {
  145. if (($model = Zayvki::findOne($id)) !== null) {
  146. return $model;
  147. }
  148.  
  149. throw new NotFoundHttpException('The requested page does not exist.');
  150. }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement