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;
- /**
- * 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(isset($_POST['Zayvki']))
- {
- $model->attributes=$_POST['Zayvki'];
- $model->zayvki_id = $_POST['Zayvki']['zayvki_id'];
- $model->category_id = $_POST['Zayvki']['category_id'];
- if($model->save())
- $this->redirect(array('view','id'=>$model->id));
- }
- $this->render('create',array(
- 'model'=>$model,
- ));
- }
- public function actionCreateiko()
- {
- $model = new Zayvki();
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
- }
- return $this->render('createiko', [
- 'model' => $model,
- ]);
- }
- /**
- * 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->loadModel($id);
- if(isset($_POST['Zayvki']))
- {
- $model->attributes=$_POST['Zayvki'];
- $model->zayvki_id = $_POST['Zayvki']['zayvki_id'];
- $model->category_id = $_POST['Zayvki']['category_id'];
- if($model->save())
- $this->redirect(array('view','id'=>$model->id));
- }
- $this->render('update',array(
- 'model'=>$model,
- ));
- }
- public function loadModel($id)
- {
- $model=Zayvki::model()->findByPk($id);
- $modelorder=Order::model()->find('zayvki_id=:zayvki_id', array(':zayvki_id'=> $id));
- $model->uslugi_id = $modelorder->uslugi_id;
- $model->category_id = $modelorder->category_id;
- if($model===null)
- throw new CHttpException(404,'The requested page does not exist.');
- return $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