Symfony2で入れると便利なBundle
DoctrineFixturesBundle
データ投入用のBundle。インストール方法、使い方はDoctrineFixturesBundleを参照。また、ファンクショナルテストのデータロードに使うSymfony2にDoctrineFixturesBundleを導入してPHPUnitと連動させるも参考になる。
KnpPagenatorBundle
ページング処理をわりと簡単に実装できるBundle。インストール方法はGitHubのKnpPaginatorBundleを参照。
Twitter Bootstrapと連携する
Twitter Bootstrapと連携するようにするには出力されるHTMLを少し変えないといけないので、以下のように行う。
テンプレートファイルを用意
適当な位置(Foo/BarBundle/Resources/views/Pagination/pagination.html.twigあたり)に以下のようなテンプレートファイルを用意。
{# Foo/BarBundle/Resources/views/Pagination/pagination.html.twig #} {% if pageCount > 1 %} <div class="pagination"> <ul> {% if first is defined and current != first %} <li class="first"> <a href="{{ path(route, query|merge({'page': first})) }}"><<</a> </li> {% endif %} {% if previous is defined %} <li class="previous"> <a href="{{ path(route, query|merge({'page': previous})) }}"><</a> </li> {% endif %} {% for page in pagesInRange %} {% if page != current %} <li class="page"> <a href="{{ path(route, query|merge({'page': page})) }}">{{ page }}</a> </li> {% else %} <li class="active"><a href="#">{{ page }}</a></li> {% endif %} {% endfor %} {% if next is defined %} <li class="next"> <a href="{{ path(route, query|merge({'page': next})) }}">></a> </li> {% endif %} {% if last is defined and current != last %} <li class="last"> <a href="{{ path(route, query|merge({'page': last})) }}">>></a> </li> {% endif %} </ul> </div> {% endif %}
parameters.ymlにテンプレートファイルの指定を書く
parameters: knp_paginator.template.pagination: FooBarBundle:Pagination:pagination.html.twig
SonataGoutteBundle
webスクレイピングライブラリのGoutteを組み込むためのライブラリ。GoutteはSymfony\Component\BrowserKit\Clientを継承しているので、コントローラのファンクショナルテストを書くときと同じような感じで外部アクセスが可能。インストール方法などはGitHubのSonataGoutteBundleのページを参照。