pmtpenza

Untitled

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