Skip to content

Commit

Permalink
Merge pull request #140 from M1saka10010/master
Browse files Browse the repository at this point in the history
fix: 题目列表翻页之后搜索失效,每页题目数量控制失效
  • Loading branch information
M1saka10010 authored Dec 16, 2023
2 parents 8c1d5d9 + ba6bb18 commit 89186bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions controllers/ProblemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function behaviors()
* Lists all Problem models.
* @return mixed
*/
public function actionIndex($showTags = 0, $page = 1, $tag = '')
public function actionIndex($showTags = 0, $page = 1, $per_page = 50, $tag = '', $q = '')
{

if (Yii::$app->setting->get('isContestMode') && (Yii::$app->user->isGuest || (!Yii::$app->user->identity->isAdmin()))) {
Expand All @@ -53,16 +53,20 @@ public function actionIndex($showTags = 0, $page = 1, $tag = '')
if (Yii::$app->request->get('tag') != '') {
$query->andWhere('tags LIKE :tag', [':tag' => '%' . Yii::$app->request->get('tag') . '%']);
}
if (($post = Yii::$app->request->post())) {
$query->orWhere(['like', 'title', $post['q']])
->orWhere(['like', 'id', $post['q']])
->orWhere(['like', 'source', $post['q']]);
if (Yii::$app->request->get('q') != '') {
$query->orWhere(['like', 'title', $q])->orWhere(['like', 'id', $q])->orWhere(['like', 'source', $q]);
}
// if (($post = Yii::$app->request->post())) {
// $query->orWhere(['like', 'title', $post['q']])
// ->orWhere(['like', 'id', $post['q']])
// ->orWhere(['like', 'source', $post['q']]);
// }
$query->andWhere('status<>' . Problem::STATUS_HIDDEN);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 50
'pageSize' => $per_page,
'pageSizeParam' => 'per_page'
]
]);

Expand Down Expand Up @@ -95,7 +99,8 @@ public function actionIndex($showTags = 0, $page = 1, $tag = '')
'solvedProblem' => $solvedProblem,
'showTags' => $showTags,
'page' => $page,
'tag' => $tag
'tag' => $tag,
'q' => $q
]);
}

Expand Down
4 changes: 2 additions & 2 deletions views/problem/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@



<?= Html::beginForm('', 'post') ?>
<?= Html::beginForm('/problem/index', 'get') ?>

<div class="row">
<div class="input-group">
<div class="col-lg-6" style="margin-bottom: 1rem;">
<?= Html::textInput('q', '', ['class' => 'form-control', 'placeholder' => '题号 / 标题 / 来源']) ?>
<?= Html::textInput('q', $q, ['class' => 'form-control', 'placeholder' => '题号 / 标题 / 来源']) ?>
</div>

<div class="col-lg-6" style="margin-bottom: 1rem;">
Expand Down

0 comments on commit 89186bd

Please sign in to comment.