teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

6

文言の修正

2017/06/13 11:00

投稿

yuuuui
yuuuui

スコア59

title CHANGED
File without changes
body CHANGED
@@ -50,7 +50,7 @@
50
50
  }
51
51
  ```
52
52
 
53
- ###修正後↓
53
+ ###修正後↓(解決)
54
54
  ```PHP
55
55
  SearchController.php
56
56
 

5

修正後のソースを修正

2017/06/13 11:00

投稿

yuuuui
yuuuui

スコア59

title CHANGED
File without changes
body CHANGED
@@ -2,7 +2,7 @@
2
2
  solrの全文検索システムを作っています。
3
3
  ページネーション機能を実装中にページ遷移先にデータが参照されませんでした。
4
4
 
5
- ###pagination実装ソースコード(Laravelのカスタムページネータを使用)
5
+ ###pagination実装ソースコード(Laravelのカスタムページネータを使用)修正前
6
6
  ```PHP
7
7
  SearchController.php
8
8
 
@@ -58,10 +58,6 @@
58
58
  $query = $this->client->createSelect();
59
59
  $query->setQuery($request['keyword']);
60
60
 
61
- //コメントアウト
62
- //$resultset = $this->client->select($query);
63
-
64
-
65
61
  $perPage = $query->getRows(); //defalutの10件
66
62
  $startPage = $query->getStart(); //defalutの0件
67
63
 
@@ -71,22 +67,25 @@
71
67
  // 配列のoffset位置からperPage分の配列を切り抜く
72
68
  $offset = ( $page * $perPage ) - $perPage;
73
69
 
74
- //追加
75
- $sliced = $query->setStart($offset)->setRows($perPage);
70
+ $sliced = $query->setStart($offset)->setRows($perPage);
76
- dump($sliced);
71
+ dump($sliced);
77
-
78
72
 
73
+ //結果
74
+ $resultset = $this->client->select($query);
75
+
79
- //コメントアウト
76
+ //結果を全件取得
80
- //$sliced = array_slice((array)$resultset, $offset, $perPage, true);
77
+ $resultset_total = $resultset->getNumFound();
81
78
 
82
79
  $paginator = new LengthAwarePaginator(
83
80
  $sliced,
84
81
  $resultset_total,
85
82
  $perPage,
86
- $page, //NULLから$pageへ変更
83
+ $page,
87
84
  [
88
85
  'page' => $page,
89
86
  'path' => Paginator::resolveCurrentPath(),
87
+ 'query' => ['keyword' => $request['keyword']],
88
+
90
89
  ]
91
90
 
92
91
  );

4

修正後のソース修正

2017/06/13 10:58

投稿

yuuuui
yuuuui

スコア59

title CHANGED
File without changes
body CHANGED
@@ -58,10 +58,10 @@
58
58
  $query = $this->client->createSelect();
59
59
  $query->setQuery($request['keyword']);
60
60
 
61
+ //コメントアウト
61
- $resultset = $this->client->select($query);
62
+ //$resultset = $this->client->select($query);
62
63
 
63
64
 
64
-
65
65
  $perPage = $query->getRows(); //defalutの10件
66
66
  $startPage = $query->getStart(); //defalutの0件
67
67
 
@@ -70,8 +70,14 @@
70
70
 
71
71
  // 配列のoffset位置からperPage分の配列を切り抜く
72
72
  $offset = ( $page * $perPage ) - $perPage;
73
+
74
+ //追加
75
+ $sliced = $query->setStart($offset)->setRows($perPage);
73
- dump($offset);
76
+ dump($sliced);
77
+
78
+
79
+ //コメントアウト
74
- $sliced = array_slice((array)$resultset, $offset, $perPage, true);
80
+ //$sliced = array_slice((array)$resultset, $offset, $perPage, true);
75
81
 
76
82
  $paginator = new LengthAwarePaginator(
77
83
  $sliced,
@@ -95,7 +101,7 @@
95
101
 
96
102
  ```
97
103
  ページネーションはブラウザに表示されているが
98
- 2ページ目を押下するとURLはhttp://xxx.x.x.x/list?kayword=〇〇&page=2となりますが
104
+ 2ページ目を押下するとURLはhttp://xxx.x.x.x/list?keyword=〇〇&page=2となりますが
99
105
  結果は表示されない。
100
106
  (1ページ目に全件表示されている)
101
107
 

3

修正後ソースを修正

2017/06/13 09:18

投稿

yuuuui
yuuuui

スコア59

title CHANGED
File without changes
body CHANGED
@@ -66,20 +66,15 @@
66
66
  $startPage = $query->getStart(); //defalutの0件
67
67
 
68
68
 
69
+ $page = max(0, Paginator::resolveCurrentPage()); //-1を削除
69
70
 
70
- $perPage = 10;
71
- $startPage = $query->getStart();
72
-
73
- $page = max(0, Paginator::resolveCurrentPage() - 1);
74
-
75
- //コメントアウト↓
76
- //foreach ($resultset as $document) {
71
+ // 配列のoffset位置からperPage分の配列を切り抜く
77
-
72
+ $offset = ( $page * $perPage ) - $perPage;
78
- //コメントアウト↓
73
+ dump($offset);
79
- //$sliced = array_slice((array)$document->id, $page * $perPage, $perPage);
74
+ $sliced = array_slice((array)$resultset, $offset, $perPage, true);
80
-
75
+
81
76
  $paginator = new LengthAwarePaginator(
82
- $resultset,
77
+ $sliced,
83
78
  $resultset_total,
84
79
  $perPage,
85
80
  $page, //NULLから$pageへ変更
@@ -89,8 +84,6 @@
89
84
  ]
90
85
 
91
86
  );
92
-
93
- // }
94
87
  ```
95
88
 
96
89
  ```PHP

2

文法の修正

2017/06/13 04:56

投稿

yuuuui
yuuuui

スコア59

title CHANGED
File without changes
body CHANGED
@@ -90,7 +90,7 @@
90
90
 
91
91
  );
92
92
 
93
- }
93
+ // }
94
94
  ```
95
95
 
96
96
  ```PHP

1

修正後のソースを更新

2017/06/12 10:09

投稿

yuuuui
yuuuui

スコア59

title CHANGED
File without changes
body CHANGED
@@ -37,7 +37,7 @@
37
37
  // ページネータインスタンス生成
38
38
  $paginator = new LengthAwarePaginator(
39
39
  $sliced,
40
- $resultset_total,
40
+ $resultset_total,//$resultset_total = $resultset->getNumFound();
41
41
  $perPage,
42
42
  null,
43
43
  [
@@ -50,7 +50,50 @@
50
50
  }
51
51
  ```
52
52
 
53
+ ###修正後↓
53
54
  ```PHP
55
+ SearchController.php
56
+
57
+
58
+ $query = $this->client->createSelect();
59
+ $query->setQuery($request['keyword']);
60
+
61
+ $resultset = $this->client->select($query);
62
+
63
+
64
+
65
+ $perPage = $query->getRows(); //defalutの10件
66
+ $startPage = $query->getStart(); //defalutの0件
67
+
68
+
69
+
70
+ $perPage = 10;
71
+ $startPage = $query->getStart();
72
+
73
+ $page = max(0, Paginator::resolveCurrentPage() - 1);
74
+
75
+ //コメントアウト↓
76
+ //foreach ($resultset as $document) {
77
+
78
+ //コメントアウト↓
79
+ //$sliced = array_slice((array)$document->id, $page * $perPage, $perPage);
80
+
81
+ $paginator = new LengthAwarePaginator(
82
+ $resultset,
83
+ $resultset_total,
84
+ $perPage,
85
+ $page, //NULLから$pageへ変更
86
+ [
87
+ 'page' => $page,
88
+ 'path' => Paginator::resolveCurrentPath(),
89
+ ]
90
+
91
+ );
92
+
93
+ }
94
+ ```
95
+
96
+ ```PHP
54
97
  search.blade.php
55
98
 
56
99
  <ul>