2017-06-14 1 views
0

今日初めて初めてsymfony 3プロジェクトにKnpPaginatorBundleをインストールし、奇妙なバグが発生しました。前と次のボタンの代わりに、 "«label_previous»......と" label_next» "を取得します。前にconfig.ymlに言語を追加して実験を行ったことがありますが、今日のバージョンに戻しても、まだボタンのラベルが正しく表示されていません。KnpPaginatorBundleから間違ったラベルを取得する

Picture of the pages navigation

と私のconfig.yml

imports: 
    - { resource: parameters.yml } 
    - { resource: security.yml } 
    - { resource: services.yml } 

# Put parameters here that don't need to change on each machine where the app is deployed 
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration 
parameters: 
    locale: en 

framework: 
    #esi: ~ 
    #translator: { fallbacks: ['%locale%'] } 
    secret: '%secret%' 
    router: 
     resource: '%kernel.root_dir%/config/routing.yml' 
     strict_requirements: ~ 
    form: ~ 
    csrf_protection: ~ 
    validation: { enable_annotations: true } 
    #serializer: { enable_annotations: true } 
    templating: 
     engines: ['twig'] 
    default_locale: '%locale%' 
    trusted_hosts: ~ 
    trusted_proxies: ~ 
    session: 
     # http://symfony.com/doc/current/reference/configuration/framework.html#handler-id 
     handler_id: session.handler.native_file 
     save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%" 
    fragments: ~ 
    http_method_override: true 
    assets: ~ 
    php_errors: 
     log: true 

# Twig Configuration 
twig: 
    debug: '%kernel.debug%' 
    strict_variables: '%kernel.debug%' 
    form_themes: 
     - bootstrap_3_layout.html.twig 

    globals: 
     brands: '@list_brands' 

# Doctrine Configuration 
doctrine: 
    dbal: 
     driver: pdo_mysql 
     host: '%database_host%' 
     port: '%database_port%' 
     dbname: '%database_name%' 
     user: '%database_user%' 
     password: '%database_password%' 
     charset: UTF8 
     # if using pdo_sqlite as your database driver: 
     # 1. add the path in parameters.yml 
     #  e.g. database_path: "%kernel.root_dir%/../var/data/data.sqlite" 
     # 2. Uncomment database_path in parameters.yml.dist 
     # 3. Uncomment next line: 
     #path: '%database_path%' 

    orm: 
     auto_generate_proxy_classes: '%kernel.debug%' 
     naming_strategy: doctrine.orm.naming_strategy.underscore 
     auto_mapping: true 

# Swiftmailer Configuration 
swiftmailer: 
    transport: '%mailer_transport%' 
    host: '%mailer_host%' 
    username: '%mailer_user%' 
    password: '%mailer_password%' 
    spool: { type: memory } 

#KNP 
knp_paginator: 
    page_range: 5      # default page range used in pagination control 
    default_options: 
     page_name: page    # page query parameter name 
     sort_field_name: sort   # sort field query parameter name 
     sort_direction_name: direction # sort direction query parameter name 
     distinct: true     # ensure distinct results, useful when ORM queries are using GROUP BY statements 
    template: 
     pagination: 'KnpPaginatorBundle:Pagination:twitter_bootstrap_v3_pagination.html.twig'  # sliding pagination controls template 
     sortable: 'KnpPaginatorBundle:Pagination:sortable_link.html.twig' # sort link template 

twitter_bootstrap_v3_pagination.html.twigファイル

{# 
/** 
* @file 
* Twitter Bootstrap v3 Sliding pagination control implementation. 
* 
* View that can be used with the pagination module 
* from the Twitter Bootstrap CSS Toolkit 
* http://getbootstrap.com/components/#pagination 
* 
* @author Pablo Díez <[email protected]> 
* @author Jan Sorgalla <[email protected]> 
* @author Artem Ponomarenko <[email protected]> 
* @author Artem Zabelin <[email protected]> 
*/ 
#} 

{% if pageCount > 1 %} 
    <ul class="pagination"> 

    {% if previous is defined %} 
     <li> 
      <a rel="prev" href="{{ path(route, query|merge({(pageParameterName): previous})) }}">&laquo;&nbsp;{{ 'label_previous'|trans({}, 'KnpPaginatorBundle') }}</a> 
     </li> 
    {% else %} 
     <li class="disabled"> 
      <span>&laquo;&nbsp;{{ 'label_previous'|trans({}, 'KnpPaginatorBundle') }}</span> 
     </li> 
    {% endif %} 

    {% if startPage > 1 %} 
     <li> 
      <a href="{{ path(route, query|merge({(pageParameterName): 1})) }}">1</a> 
     </li> 
     {% if startPage == 3 %} 
      <li> 
       <a href="{{ path(route, query|merge({(pageParameterName): 2})) }}">2</a> 
      </li> 
     {% elseif startPage != 2 %} 
     <li class="disabled"> 
      <span>&hellip;</span> 
     </li> 
     {% endif %} 
    {% endif %} 

    {% for page in pagesInRange %} 
     {% if page != current %} 
      <li> 
       <a href="{{ path(route, query|merge({(pageParameterName): page})) }}">{{ page }}</a> 
      </li> 
     {% else %} 
      <li class="active"> 
       <span>{{ page }}</span> 
      </li> 
     {% endif %} 

    {% endfor %} 

    {% if pageCount > endPage %} 
     {% if pageCount > (endPage + 1) %} 
      {% if pageCount > (endPage + 2) %} 
       <li class="disabled"> 
        <span>&hellip;</span> 
       </li> 
      {% else %} 
       <li> 
        <a href="{{ path(route, query|merge({(pageParameterName): (pageCount - 1)})) }}">{{ pageCount -1 }}</a> 
       </li> 
      {% endif %} 
     {% endif %} 
     <li> 
      <a href="{{ path(route, query|merge({(pageParameterName): pageCount})) }}">{{ pageCount }}</a> 
     </li> 
    {% endif %} 

    {% if next is defined %} 
     <li> 
      <a rel="next" href="{{ path(route, query|merge({(pageParameterName): next})) }}">{{ 'label_next'|trans({}, 'KnpPaginatorBundle') }}&nbsp;&raquo;</a> 
     </li> 
    {% else %} 
     <li class="disabled"> 
      <span>{{ 'label_next'|trans({}, 'KnpPaginatorBundle') }}&nbsp;&raquo;</span> 
     </li> 
    {% endif %} 
    </ul> 
{% endif %} 
+0

:私はあなたの質問を理解しない –

+0

@leo_apをtwitter_bootstrap_v3_pagination.html.twig'それはこのようなものでなければなりません。 – symfonypleb

+0

knp_paginatorは、テンプレートファイルを使用してテンプレートをレンダリングします。あなたのconfig.ymlの最後の2行を見て、2つのファイルが表示されます。そのうちの1つは、コード –

答えて

1

このテンプレートファイルtwitter_bootstrap_v3_pagination.html.twigは、名前を取得するにはtrans小枝フィルタを使用していますラベルのあなたはこれを見ることができ、例えば、部分的に:

<span>&laquo;&nbsp;{{ 'label_previous'|trans({}, 'KnpPaginatorBundle') }}</span>

transフィルタ(http://symfony.com/doc/current/reference/twig_reference.html#trans)は、特定のコンテキスト内の翻訳のコンフィギュレーション・ファイルを検索しようとします。あなたのコンテキストはKnpPaginatorBundleなので、このバンドル内の翻訳ファイルを検索します。ここを見てください:https://github.com/KnpLabs/KnpPaginatorBundle/tree/master/Resources/translations

ロケールごとに1つの翻訳ファイルがありますが、アプリケーションのデフォルトロケールがこのリストにない場合は翻訳されません。

ただし、ロケールがenであり、それでも動作しない場合は、独自のテンプレートを作成してラベルを手動で入力することができます。

3つの簡単な手順でこれを行います。

1º:app/Resources/viewsフォルダの下にpagination.twig.html(またはそのような名前)という名前の新しいファイルを作成します。

2º:ファイルtwitter_bootstrap_v3_pagination.html.twigのコードをコピーして、作成した新しいファイルに貼り付けます。次に、transフィルターを参照する行を変更します。例:

ライン: <span>&laquo;&nbsp;{{ 'label_previous'|trans({}, 'KnpPaginatorBundle') }}</span>

あなたがに編集する必要があります: <span>&laquo;&nbsp; Previous</span>

3º:あなたのapp/config/config.yml knp_paginator /テンプレート/ページネーションキーでファイルを変更するには。ページネーション:: `KnpPaginatorBundleのコードがどのように

#KNP 
knp_paginator: 
    page_range: 5      # default page range used in pagination control 
    default_options: 
     page_name: page    # page query parameter name 
     sort_field_name: sort   # sort field query parameter name 
     sort_direction_name: direction # sort direction query parameter name 
     distinct: true     # ensure distinct results, useful when ORM queries are using GROUP BY statements 
    template: 
     pagination: 'pagination.html.twig' 
     sortable: 'KnpPaginatorBundle:Pagination:sortable_link.html.twig' # sort link template 
+1

私の設定では、この行のコメントを外すだけでした。翻訳者:{fallbacks:['%locale%']} – symfonypleb

関連する問題