Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace backend\controllers;
- use Yii;
- use backend\models\Zayvki;
- use backend\models\ZayvkiSearch;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- use backend\models\Order;
- use backend\models\OrderForm;
- /**
- * ZayvkiController implements the CRUD actions for Zayvki model.
- */
- class ZayvkiController extends Controller
- {
- /**
- * {@inheritdoc}
- */
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['POST'],
- ],
- ],
- ];
- }
- /**
- * Lists all Zayvki models.
- * @return mixed
- */
- public function actionIndex()
- {
- $searchModel = new ZayvkiSearch();
- $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
- return $this->render('index', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- ]);
- }
- /**
- * Displays a single Zayvki model.
- * @param integer $id
- * @return mixed
- * @throws NotFoundHttpException if the model cannot be found
- */
- public function actionView($id)
- {
- return $this->render('view', [
- 'model' => $this->findModel($id),
- ]);
- }
- /**
- * Creates a new Zayvki model.
- * If creation is successful, the browser will be redirected to the 'view' page.
- * @return mixed
- */
- public function actionCreate()
- {
- $model = new Zayvki();
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- $order = new Order();
- $order->load(Yii::$app->request->post());
- $order->uslugi_id = Yii::$app->request->post('Zayvki')['uslugi_id'];
- $order->hours = Yii::$app->request->post('Zayvki')['hours'];
- $order->date = Yii::$app->request->post('Zayvki')['date'];
- $order->category_id = 3;
- $order->link('zayvki', $model);
- return $this->redirect(['view', 'id' => $model->id]);
- }
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- public function actionCreateiko()
- {
- $model = new Zayvki();
- $orders = [new OrderForm()];
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
- }
- return $this->render('createiko', [
- 'model' => $model,
- 'orders' => $order,
- ]);
- }
- /**
- * Updates an existing Zayvki model.
- * If update is successful, the browser will be redirected to the 'view' page.
- * @param integer $id
- * @return mixed
- * @throws NotFoundHttpException if the model cannot be found
- */
- public function actionUpdate($id)
- {
- $model = $this->findModel($id);
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
- }
- return $this->render('update', [
- 'model' => $model,
- ]);
- }
- /**
- * Deletes an existing Zayvki model.
- * If deletion is successful, the browser will be redirected to the 'index' page.
- * @param integer $id
- * @return mixed
- * @throws NotFoundHttpException if the model cannot be found
- */
- public function actionDelete($id)
- {
- $this->findModel($id)->delete();
- return $this->redirect(['index']);
- }
- /**
- * Finds the Zayvki model based on its primary key value.
- * If the model is not found, a 404 HTTP exception will be thrown.
- * @param integer $id
- * @return Zayvki the loaded model
- * @throws NotFoundHttpException if the model cannot be found
- */
- protected function findModel($id)
- {
- if (($model = Zayvki::findOne($id)) !== null) {
- return $model;
- }
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement