【问题标题】:pagination not working when clicking on page number单击页码时分页不起作用
【发布时间】:2016-11-29 22:16:21
【问题描述】:

我正在使用 laravel 分页。当我点击下一页或任何页码时,什么也没有发生。 控制器功能

public function getIndex()
{
    $articles = Inspector::paginate(15);
    return view('admin.inspector.test', compact('articles'));
}

查看文件

     <table class="table table-bordered" id="mytable">
                        <thead>
                            <tr>
                                <th>Sr. No.&nbsp;</th>
                                <th>Email</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach ($articles as $article)
                            <tr>
                            <td>{{ $article->id }}</td>
                            <td>{{ $article->email }}</td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                    {!! $articles->render() !!}

非常感谢任何帮助...谢谢...

【问题讨论】:

  • 错误是什么?你试过用{!! str_replace('/?', '?', $articles-&gt;render()) !!}

标签: php laravel pagination laravel-5.1


【解决方案1】:
public function getIndex()
{
    return view('admin.inspector.test');
}

只是在调用动作时返回视图。不要从控制器发送任何数据,只需加载视图, 当视图加载时,使用分页方法获取数据库连接。并呈现如下分页

<?php $articles = DB::connection('table_name')->where('if any condition')->get(); ?>
    <table class="table table-bordered" id="mytable">
                            <thead>
                                <tr>
                                    <th>Sr. No.&nbsp;</th>
                                    <th>Email</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach ($articles as $article)
                                <tr>
                                <td>{{ $article->id }}</td>
                                <td>{{ $article->email }}</td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                        {!! $articles->render() !!}

【讨论】:

  • 您能否详细说明一下...如果我不返回带有视图的数据,它应该如何从数据库中获取数据...!
  • 投下你的答案
  • 从视图中调用数据库连接是非常糟糕的做法。所以这种方式是不可行的。
猜你喜欢
  • 1970-01-01
  • 2023-04-08
  • 2014-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-06
  • 1970-01-01
相关资源
最近更新 更多