让我们考虑一个例子
https://www.example.net/xyz?page=2
@recipes_blueprint.route('/<int:recipe_id>', methods=['POST'])
@login_required
def edit_recipe(recipe_id):
form = UpdateRecipeForm()
that_recipe = Recipe.get_or_none(Recipe.id == recipe_id)
recipe_owner = User.get_or_none(User.id == that_recipe.user_id)
if form.validate_on_submit():
if recipe_owner != current_user:
flash("Only owner of the recipe can amend the details", "danger")
return redirect(url_for('recipes.read_recipe', recipe_id=recipe_id))
else:
if "picture" not in request.files:
flash("No picture key in request.files", 'danger')
return redirect(url_for('recipes.read_recipe', recipe_id=recipe_id))
file = request.files['picture']
if file.filename == '':
flash("Please select a file", 'danger')
return redirect(url_for('users.update_user'))
if file and allowed_file(file.filename):
file.filename = secure_filename(file.filename)
output = upload_file_to_s3(file, app.config['S3_BUCKET'])
updated_recipe = Recipe.update(
title=form.data['title'],
description=form.data['description'],
picture=output
).where(Recipe.user_id == recipe_owner.id)
updated_recipe.execute()
flash("Recipe updated successfully", "success")
return redirect(url_for('recipes.read_recipe', recipe_id=recipe_id))
return render_template('read_that_recipe.html', recipe=that_recipe, form=form)
我完成了“ dd($ variable);”在功能上。给出了
的结果Route::get('/xyz', 'controller@getpages');
public function getpages() {
$variable=Model::paginate(10);
dd($variable);
}
dd($ request);
LengthAwarePaginator {#1209 ▼
#total: 4341
#lastPage: 435
#items: Collection {#1211 ▶}
#perPage: 10
#currentPage: 1
#path: "www.example.net/xyz"
#query: []
#fragment: null
#pageName: "page"
}
dd($ request-> all());
显示
Request {#38 ▼
#json: null
#convertedFiles: null
#userResolver: Closure {#1028 ▶}
#routeResolver: Closure {#1029 ▶}
+attributes: ParameterBag {#40 ▶}
+request: ParameterBag {#46 ▶}
+query: ParameterBag {#46 ▶}
+server: ServerBag {#42 ▶}
+files: FileBag {#43 ▶}
+cookies: ParameterBag {#41 ▶}
+headers: HeaderBag {#44 ▶}
#content: null
#languages: null
#charsets: null
#encodings: null
#acceptableContentTypes: null
#pathInfo: "/xyz"
#requestUri: "/xyz?page=2"
#baseUrl: ""
#basePath: null
#method: "GET"
#format: null
#session: Store {#112 ▶}
#locale: null
#defaultLocale: "en"
-isForwardedValid: true
}
出现错误的站点中的。但是其他分页正常的网站。给出以下输出。
array:1 [▼
"/xyz" => null
]
代替 #currentPage:2 。它工作正常,但是从昨天开始,它在整个网站上都在发生。那么我该如何解决呢?
注意:我已经在多页站点中使用了相同的代码。但它不仅在其中起作用
我在这里遇到了适当的问题。在我们整个站点中,传递给控制者。并在验证中。没有提及我该怎么解决。
答案 0 :(得分:1)
htaccess文件损坏
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
#RewriteEngine On
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
#RewriteCond %{THE_REQUEST} ^.*/index\.php
#RewriteRule ^(.*)index.php$ /$1 [R=301,L]
##Redirect 301 /index.php https://www.example.net/
#RewriteEngine On
#RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
#RewriteCond %{HTTP_HOST} !^www. [NC]
#RewriteRule ^(.*)$ https://www.example.net/$1 [L,R=301]
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
RewriteRule ^api/(.*)?$ http://127.0.0.1:8888/$1 [P,L]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
修正的htaccess文件
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
#RewriteEngine On
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ /index.php?/$1 [L]
#RewriteCond %{THE_REQUEST} ^.*/index\.php
#RewriteRule ^(.*)index.php$ /$1 [R=301,L]
##Redirect 301 /index.php https://www.example.net/
#RewriteEngine On
#RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
#RewriteCond %{HTTP_HOST} !^www. [NC]
#RewriteRule ^(.*)$ https://www.example.net/$1 [L,R=301]
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
RewriteRule ^api/(.*)?$ http://127.0.0.1:8888/$1 [P,L]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
答案 1 :(得分:0)
我已经尝试过您的代码,对我来说很好。根据给定的信息无法找到代码的问题。如果它不起作用,请在控制器中设置currentPage操作。所以您的控制器就像
public function getpages(Request $request) {
Paginator::currentPageResolver(function() use ($request){
return $request->page;
});
$variable=Model::paginate(10);
dd($variable);
}