我有一个与post方法配合使用的搜索表单,但是问题是分页链接不起作用。除第一页外,其他所有页面均为空白页。我在某处读到过分页不适用于POST
方法。
但是,当我更改表单并路由到“ get”方法时,即使在第一页上,我也会得到空白页。什么都不会显示。
这是我的路线
Route::get('reports/search','ReportsController@search');
这是我的表单
<form method="get" class="form-horizontal" action="{{action('ReportsController@search')}}">
<!-- {{csrf_field()}} used only with POST-->
<input type="text" name="search" id="search">
<button type="submit" class="btn btn-primary"> Submit</button>
</form>
这是我的控制器代码
public function search(Request $request)
{
$showData = sys_data::paginate(10);
return view('reports-data-view', compact('showData'));
}
问题是,当我将表单和路由方法更改为POST
时,它可以工作,但是分页链接显示空白页。
当我将方法更改为GET
时,它不起作用。当我点击“提交”按钮时,显示空白页面。
任何帮助将不胜感激。提前致谢。
答案 0 :(得分:0)
在您的表单中使用
import itertools
from collections import defaultdict
n = 10
print("Number of Tetris pieces up to size", n)
# Times:
# n is number of blocks
# - Python O(exp(n)^2): 10 blocks 2.5m
# - Python O(exp(n)): 10 blocks 2.5s, 11 blocks 10.9s, 12 block 33s, 13 blocks 141s (800MB memory)
# - Other implementation:
smallest_piece = [(0, 0)] # We represent a piece as a list of block positions
pieces_of_size = {
1: [smallest_piece],
}
# Returns a list of all possible pieces made by adding one block to given piece
def possible_expansions(piece):
# No flatMap in Python 2/3:
# https://stackoverflow.com/questions/21418764/flatmap-or-bind-in-python-3
positions = set(itertools.chain.from_iterable(
[(x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)] for (x, y) in piece
))
# Time complexity O(n^2) can be improved
# For each valid position, append to piece
expansions = []
for p in positions:
if not p in piece:
expansions.append(piece + [p])
return expansions
def rotate_90_cw(piece):
return [(y, -x) for (x, y) in piece]
def canonical(piece):
min_x = min(x for (x, y) in piece)
min_y = min(y for (x, y) in piece)
res = sorted((x - min_x, y - min_y) for (x, y) in piece)
return res
def hash_piece(piece):
return hash(tuple(piece))
def expand_pieces(pieces):
expanded = []
#[
# 332322396: [[(1,0), (0,-1)], [...]],
# 323200700000: [[(1,0), (0,-2)]]
#]
# Multimap because two different pieces can happen to have the same hash
expanded_hashes = defaultdict(list)
for piece in pieces:
for e in possible_expansions(piece):
exp = canonical(e)
is_new = True
if exp in expanded_hashes[hash_piece(exp)]:
is_new = False
for rotation in range(3):
exp = canonical(rotate_90_cw(exp))
if exp in expanded_hashes[hash_piece(exp)]:
is_new = False
if is_new:
expanded.append(exp)
expanded_hashes[hash_piece(exp)].append(exp)
return expanded
for i in range(2, n + 1):
pieces_of_size[i] = expand_pieces(pieces_of_size[i - 1])
print("Pieces with {} blocks: {}".format(i, len(pieces_of_size[i])))
答案 1 :(得分:0)
没关系,我知道了。
实际上,由于GET链接是/ reports / search,因此默认情况下该请求将进入控制器的“ show($ id)”函数,因为该请求将链接中的“ research”作为参数。
我所做的就是,将路由更改为“ / reports / search / view”,它开始工作并转到ReportsController中正确的自定义函数“ search()”。