|
- <?php
-
- namespace backend\modules\motorcade\controllers;
-
- use backend\modules\motorcade\models\searchProtocol;
- use Yii;
- use backend\modules\motorcade\models\BaseBusProtocol;
- use yii\helpers\Url;
- use yii\web\NotFoundHttpException;
-
- /**
- * BusProtocolController implements the CRUD actions for BaseBusProtocol model.
- */
- class BusProtocolController extends BaseController
- {
- public $layout = "@backend/modules/motorcade/views/layouts/iframe_new";
-
- /**
- * Lists all BaseBusProtocol models.
- * @param $BUS_ID string|integer 修改车辆基础信息和挂靠费用都是用的这里,以$BUS_ID为区分,会影响页面渲染
- * @return mixed
- */
- public function actionIndex($BUS_ID = '')
- {
- $searchModel = new searchProtocol();
- $searchModel->BUS_ID = $BUS_ID;
- if($BUS_ID === ''){
- $searchModel->PAID = 0;
- }
- $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
-
- return $this->render('index', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- 'all' => $BUS_ID === '' ? true : false
- ]);
- }
-
- /**
- * Creates a new BaseBusProtocol model.
- * If creation is successful, the browser will be redirected to the 'view' page.
- * @param $BUS_ID integer
- * @return mixed
- */
- public function actionCreate($BUS_ID)
- {
- $model = new BaseBusProtocol();
-
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return "<script>z.pjaxFinish('success', '添加成功', '#float-div');$.pjax.reload({container:'#protocol-pjax', timeout: false, replace: false, url: '" .
- Url::to(['index', 'BUS_ID' => $model->BUS_ID]) . "'})</script>";
- } else {
- $model->BUS_ID = $BUS_ID;
- return $this->render('_form', [
- 'model' => $model,
- ]);
- }
- }
-
- /**
- * Updates an existing BaseBusProtocol model.
- * If update is successful, the browser will be redirected to the 'view' page.
- * @param integer $id
- * @return mixed
- */
- public function actionUpdate($id)
- {
- $model = $this->findModel($id);
-
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return "<script>z.pjaxFinish('success', '修改成功', '#float-div');$.pjax.reload({container:'#protocol-pjax', timeout: false, replace: false, url: '" .
- Url::to(['index', 'BUS_ID' => $model->BUS_ID]) . "'})</script>";
- } else {
- return $this->render('_form', [
- 'model' => $model,
- ]);
- }
- }
-
- /**
- * Deletes an existing BaseBusProtocol model.
- * If deletion is successful, the browser will be redirected to the 'index' page.
- * @param integer $id
- * @return mixed
- */
- public function actionDelete($id)
- {
- $model = $this->findModel($id);
- $model->delete();
-
- $function = "$.pjax.reload({container:'#protocol-pjax', timeout: false, replace: false, url: '" .
- Url::to(['index', 'BUS_ID' => $model->BUS_ID]) . "'})";
- $result = ['code' => 0, 'msg' => '删除成功!', 'callback' => $function];
- return json_encode($result);
- }
-
- /**
- * Finds the BaseBusProtocol model based on its primary key value.
- * If the model is not found, a 404 HTTP exception will be thrown.
- * @param integer $id
- * @return BaseBusProtocol the loaded model
- * @throws NotFoundHttpException if the model cannot be found
- */
- protected function findModel($id)
- {
- if (($model = BaseBusProtocol::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
- }
|