Laravel 4分页不起作用链接可以,但是在每个页面中显示所有结果 [英] Laravel 4 pagination not working links are OK but shows all results in each page

查看:78
本文介绍了Laravel 4分页不起作用链接可以,但是在每个页面中显示所有结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows 7中使用Laravel 4作曲家的全新安装中,我在routes.php中:

In a fresh installation with composer of Laravel 4 in windows 7 I have in routes.php:

Route::model('work', 'Work');
Route::get('/', function()
{
    $works = Work::all();
    $allWorks = Work::paginate(5);

    return View::make('hello', compact('works', 'allWorks'));
 });

在视图文件'hello.php'中:

And in view file 'hello.php':

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Laravel PHP Framework</title>
</head>
  <body>
    <div class="container">
        <?php foreach ($works as $work) 
    {
       echo $work->title . '<br/>';
    } 
    ?>
</div>
<?php echo $allWorks->links(); ?>
   </body>
 </html>

我有一个包含25个条目的数据库.当我导航到"/"路线时,我看到数据库的所有25个结果(所有$ work-title字段),并且在页面底部显示了分页链接.当我单击分页链接时,URL正确更改为localhost/laravel/public/?page=1 ... page = 2等,但始终显示所有25条结果.当我更改分页号(例如 $allWorks = work::paginate(7);)时,链接也会相应更改. 我认为我已经完全按照文档中的说明进行了操作,但是显然我缺少了一些东西.通过谷歌搜索,我发现.htaccess有时会干扰分页.这是我的:

I have a database with 25 entries. When I navigate to '/' route I see ALL 25 results of the database (all $work-title fields) and at the bottom the pagination links. When I click on a pagination link the url changes correctly to localhost/laravel/public/?page=1 ... page=2 etc but always showing ALL 25 results. When I change the pagination number eg $allWorks = work::paginate(7); the links change appropriately. I think I have done it exactly as in the documentation but obviously I'm missing something. By googling I saw that .htaccess interferes sometimes with pagination. Here is mine:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

我不了解正则表达式(其中没有其他内容),但是我已将其注释掉,并且似乎没有任何变化.有人可以帮忙吗?谢谢

I don't understand the regex (neither the other stuff in it) but I have commented it out and nothing seemed to change. Can anyone help? Thanks

我也有一个Work.php模型:

I also have a model Work.php:

<?php
Class Work extends Eloquent
{
 }

推荐答案

您要将两个结果都发送到视图,请在routes.php中使用以下行:

You are sending both results to the view, use the following line in routes.php:

return View::make('hello')->with('allWorks', $allWorks);

这在视图上(请注意此行<?php foreach ($allWorks as $work)中使用的变量):

And this on the View (note the variable used in this line <?php foreach ($allWorks as $work)) :

'hello.php':

'hello.php':

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Laravel PHP Framework</title>
</head>
  <body>
    <div class="container">
        <?php foreach ($allWorks as $work) 
    {
       echo $work->title . '<br/>';
    } 
    ?>
</div>
<?php echo $allWorks->links(); ?>
   </body>
 </html>

这篇关于Laravel 4分页不起作用链接可以,但是在每个页面中显示所有结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆