2016-02-26 89 views
0

我正在嘗試爲當前項目添加分頁。我對Symfony相當陌生,所以我不確定是否有可以幫助我構建的東西。我當前的代碼如下所示:Symfony中的限制,分頁

控制器類:

class MovieDisplayController extends Controller 
{ 
    public function showAction() 
    { 
     $movies = $this->getDoctrine()->getEntityManager()->getRepository('AppBundle:Movie')->FindAll(); 

     return $this->render('movies/index.html.twig', array(
      'movies' => $movies 
      )); 
    } 
} 

嫩枝模板:

{% block body %} 
    {% if movies|length == 0 %} 
     There are no movie items available. Add a movie <a href="{{ path('movie_create_form') }}">here</a> to get started. 
    {% elseif movies|length != 0 %} 
     These are the results: <br /> 
     <ul> 
      {% for x in movies %} 
       <li>Title: {{ x.title }} - Price: {{ x.price }} - <a href="{{ path('movie_edit', {id: x.id}) }}">Edit</a> - <a href="{{ path('movie_details', { id: x.id }) }}">Details</a> - <a href="{{ path('movie_delete', {id: x.id}) }}"> Delete</a></li> 
      {% endfor %} 
     </ul> 
     <a href="{{ path('movie_create_form') }}">Add more movie entries</a> 
    {% endif %} 
{% endblock %} 

這將數據庫中返回所有結果。我只想顯示5個結果(每頁的行數),並在列表下方添加分頁按鈕,我想知道這是否可行?

+0

是否使用https://github.com/KnpLabs/KnpPaginatorBundle? –

+0

我讀到它需要MariaDB,所以我不能用我想的? – Barrosy

+1

你可以,在你的情況下,你可能應該。它不需要MariaDB – Karolis

回答