pmtpenza

Untitled

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