MenuCateController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace backend\modules\common\controllers;
  3. use Yii;
  4. use common\enums\AppEnum;
  5. use common\enums\StatusEnum;
  6. use common\models\base\SearchModel;
  7. use common\models\common\MenuCate;
  8. use common\traits\Curd;
  9. use common\enums\AddonTypeEnum;
  10. use backend\controllers\BaseController;
  11. /**
  12. * Class MenuCateController
  13. * @package backend\modules\common\controllers
  14. */
  15. class MenuCateController extends BaseController
  16. {
  17. use Curd;
  18. /**
  19. * @var MenuCate
  20. */
  21. public $modelClass = MenuCate::class;
  22. /**
  23. * 首页
  24. *
  25. * @return string
  26. * @throws \yii\web\NotFoundHttpException
  27. */
  28. public function actionIndex()
  29. {
  30. $searchModel = new SearchModel([
  31. 'model' => $this->modelClass,
  32. 'scenario' => 'default',
  33. 'partialMatchAttributes' => ['title'], // 模糊查询
  34. 'defaultOrder' => [
  35. 'sort' => SORT_ASC,
  36. 'id' => SORT_ASC,
  37. ],
  38. 'pageSize' => $this->pageSize,
  39. ]);
  40. $dataProvider = $searchModel
  41. ->search(Yii::$app->request->queryParams);
  42. $dataProvider->query
  43. ->andWhere(['>=', 'status', StatusEnum::DISABLED])
  44. ->andWhere(['in', 'addon_location', ['', AddonTypeEnum::DEFAULT]])
  45. ->andWhere(['app_id' => AppEnum::BACKEND]);
  46. return $this->render($this->action->id, [
  47. 'dataProvider' => $dataProvider,
  48. 'searchModel' => $searchModel,
  49. 'cates' => Yii::$app->services->menuCate->findDefault(AppEnum::BACKEND),
  50. ]);
  51. }
  52. /**
  53. * 返回模型
  54. *
  55. * @param $id
  56. * @return \yii\db\ActiveRecord
  57. */
  58. protected function findModel($id)
  59. {
  60. /* @var $model \yii\db\ActiveRecord */
  61. if (empty($id) || empty(($model = $this->modelClass::findOne($id)))) {
  62. $model = new $this->modelClass;
  63. $model = $model->loadDefaultValues();
  64. $model->app_id = AppEnum::BACKEND;
  65. }
  66. return $model;
  67. }
  68. }
粤ICP备19079148号