pmtpenza

Untitled

Jun 21st, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 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->hours = Yii::$app->request->post('Zayvki')['hours'];
  75. $order->date = Yii::$app->request->post('Zayvki')['date'];
  76. $order->category_id = 3;
  77. $order->link('zayvki', $model);
  78. return $this->redirect(['view', 'id' => $model->id]);
  79. }
  80.  
  81.  
  82. return $this->render('create', [
  83. 'model' => $model,
  84. ]);
  85. }*/
  86.  
  87. public function actionCreate()
  88. {
  89. $model = new Zayvki();
  90. $order = [new Order()];
  91. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  92.  
  93. return $this->redirect(['view', 'id' => $model->id]);
  94. }
  95.  
  96.  
  97. return $this->render('create', [
  98.  
  99. 'model' => $model,
  100.  
  101. 'orders' => $order
  102.  
  103. ]);
  104. }
  105.  
  106. /**
  107. * Updates an existing Zayvki model.
  108. * If update is successful, the browser will be redirected to the 'view' page.
  109. * @param integer $id
  110. * @return mixed
  111. * @throws NotFoundHttpException if the model cannot be found
  112. */
  113. public function actionUpdate($id)
  114. {
  115. $model = $this->findModel($id);
  116.  
  117. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  118. return $this->redirect(['view', 'id' => $model->id]);
  119. }
  120.  
  121. return $this->render('update', [
  122. 'model' => $model,
  123. ]);
  124. }
  125.  
  126. /**
  127. * Deletes an existing Zayvki model.
  128. * If deletion is successful, the browser will be redirected to the 'index' page.
  129. * @param integer $id
  130. * @return mixed
  131. * @throws NotFoundHttpException if the model cannot be found
  132. */
  133. public function actionDelete($id)
  134. {
  135. $this->findModel($id)->delete();
  136.  
  137. return $this->redirect(['index']);
  138. }
  139.  
  140. /**
  141. * Finds the Zayvki model based on its primary key value.
  142. * If the model is not found, a 404 HTTP exception will be thrown.
  143. * @param integer $id
  144. * @return Zayvki the loaded model
  145. * @throws NotFoundHttpException if the model cannot be found
  146. */
  147. protected function findModel($id)
  148. {
  149. if (($model = Zayvki::findOne($id)) !== null) {
  150. return $model;
  151. }
  152.  
  153. throw new NotFoundHttpException('The requested page does not exist.');
  154. }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment