BaseController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace frontend\base;
  3. use common\models\CategoryCity;
  4. use Yii;
  5. use frontend\base\CommonController;
  6. use common\models\Config;
  7. /**
  8. * Default controller for the `v1` module
  9. */
  10. class BaseController extends CommonController
  11. {
  12. /**
  13. * @param $action
  14. * @return bool|void
  15. * @throws \yii\web\BadRequestHttpException
  16. */
  17. public function beforeAction($action)
  18. {
  19. parent::beforeAction($action);
  20. if (empty($action->controller->module->id) && !in_array($action->controller->module->id, \common\models\CategoryCity::find()->select(['module'])->andWhere(['state' => 1])->andWhere(['del' => 1])->andWhere(['pid' => 0])->column())) {
  21. // 默认模块
  22. $top = CategoryCity::find()->andWhere(['del' => 1, 'top' => 1])->asArray()->one()['module'];
  23. if (!empty($top)) {
  24. return $this->redirect('/' . $top)->send();
  25. }
  26. return $this->redirect('/')->send();
  27. }
  28. Yii::$app->hostserver->module['module'] = $action->controller->module->id;
  29. Yii::$app->hostserver->module['lv_one'] = CategoryCity::find()->andWhere([
  30. 'del' => 1,
  31. 'state'=> 1,
  32. 'pid' => 0
  33. ])->select(['id'])->column();
  34. Yii::$app->hostserver->module['lv_two'] = CategoryCity::find()->andWhere([
  35. 'del' => 1,
  36. 'state'=> 1,
  37. 'pid' => Yii::$app->hostserver->module['lv_one']
  38. ])->select(['id'])->all();
  39. Yii::$app->hostserver->module['web_config'] = Config::find()->asArray()->one();
  40. // p(Yii::$app->hostserver->module);die;
  41. //海南站页面页首搜索框推送楼盘
  42. if($action->controller->id != 'default'){
  43. $data = (new \common\models\House())->HotList(6);
  44. Yii::$app->view->params['hothousev2'] = $data;
  45. }
  46. return true;
  47. }
  48. }