public function actionIndex() { $this->title = Yii::$app->name; $this->description = '云建议,一个收集建议的地方。'; $tab = Yii::$app->request->get('tab'); $sessionTab = Yii::$app->session->get('tab'); if (Yii::$app->request->get('tab') === null) { if (empty($sessionTab)) { Yii::$app->session->set('tab', 'new'); $tab = 'new'; } else { $tab = $sessionTab; } } else { if (Tab::Info($tab) !== null) { Yii::$app->session->set('tab', $tab); } else { Yii::$app->session->set('tab', 'new'); $tab = 'new'; } } $tabModel = Tab::Info($tab); if (!empty($tabModel['bg']) && $tabModel['use_bg'] == 1) { $this->bg = $tabModel['bg']; } if (!empty($tabModel['bg_color'])) { $this->bg_color = $tabModel['bg_color']; } $this->canonical = Yii::$app->params['domain'] . '?tab=' . $tab; if ($tab == 'new') { $topic = (new Query())->select('topic.*, node.enname, node.name, user.username, user.avatar')->from(Topic::tableName() . ' topic')->leftJoin(Node::tableName() . ' node', 'node.id = topic.node_id')->leftJoin(User::tableName() . ' user', 'user.id = topic.user_id')->where(['node.is_hidden' => 0])->orderBy(['topic.updated_at' => SORT_DESC])->limit(Yii::$app->params['pageSize'])->all(); } else { $topic = (new Query())->select('topic.*, node.enname, node.name, user.username, user.avatar')->from(Topic::tableName())->leftJoin(Node::tableName(), 'node.id = topic.node_id')->leftJoin(User::tableName(), 'user.id = topic.user_id')->where(['in', 'topic.node_id', Tab::SubNodeId($tab)])->orderBy(['topic.updated_at' => SORT_DESC])->limit(Yii::$app->params['pageSize'])->all(); } return $this->render('index', ['topic' => $topic]); }