ConfigCateController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace backend\modules\common\controllers;
  3. use Yii;
  4. use yii\data\ActiveDataProvider;
  5. use common\traits\Curd;
  6. use common\enums\AppEnum;
  7. use common\models\common\ConfigCate;
  8. use backend\controllers\BaseController;
  9. /**
  10. * Class ConfigCateController
  11. * @package backend\modules\common\controllers
  12. */
  13. class ConfigCateController extends BaseController
  14. {
  15. use Curd;
  16. /**
  17. * @var ConfigCate
  18. */
  19. public $modelClass = ConfigCate::class;
  20. /**
  21. * Lists all Tree models.
  22. * @return mixed
  23. */
  24. public function actionIndex()
  25. {
  26. $dataProvider = new ActiveDataProvider([
  27. 'query' => $this->modelClass::find()
  28. ->where(['app_id' => AppEnum::BACKEND])
  29. ->orderBy('sort asc, created_at asc'),
  30. 'pagination' => false
  31. ]);
  32. return $this->render('index', [
  33. 'dataProvider' => $dataProvider
  34. ]);
  35. }
  36. /**
  37. * 编辑/创建
  38. *
  39. * @return mixed|string|\yii\web\Response
  40. * @throws \yii\base\ExitException
  41. */
  42. public function actionAjaxEdit()
  43. {
  44. $request = Yii::$app->request;
  45. $id = $request->get('id', '');
  46. $model = $this->findModel($id);
  47. $model->pid = $request->get('pid', null) ?? $model->pid; // 父id
  48. $model->app_id = AppEnum::BACKEND;
  49. // ajax 校验
  50. $this->activeFormValidate($model);
  51. if ($model->load($request->post())) {
  52. return $model->save()
  53. ? $this->redirect(['index'])
  54. : $this->message($this->getError($model), $this->redirect(['index']), 'error');
  55. }
  56. return $this->renderAjax('ajax-edit', [
  57. 'model' => $model,
  58. 'cateDropDownList' => Yii::$app->services->configCate->getDropDownForEdit(AppEnum::BACKEND, $id),
  59. ]);
  60. }
  61. }
粤ICP备19079148号