dongyi0210 2015-03-21 20:37
浏览 71

带查询参数的symfony2.6路由(KnpPaginatorBundle和WhiteOctoberPagerfantaBundle)

Trying to use KnpPaginatorBundle and WhiteOctoberPagerfantaBundle

If i have url

/categories/tech/plates

next page url show me

/catalog/categories/tech/plates?/catalog/categories/tech/plates=&page=2

I can not understand why this is happening :( Can anyone help? What am I doing wrong?

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // default symfony project
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),

            // additional
//          new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
            new SimpleThings\EntityAudit\SimpleThingsEntityAuditBundle(),
            new Sonata\IntlBundle\SonataIntlBundle(),
            new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
            new A2lix\TranslationFormBundle\A2lixTranslationFormBundle(),
            new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
            new Bazinga\Bundle\JsTranslationBundle\BazingaJsTranslationBundle(),

            // admin panel
            new Sonata\CoreBundle\SonataCoreBundle(),
            new Sonata\BlockBundle\SonataBlockBundle(),
            new Knp\Bundle\MenuBundle\KnpMenuBundle(),
            new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
            new Sonata\AdminBundle\SonataAdminBundle(),
            new Application\Sonata\AdminBundle\ApplicationSonataAdminBundle(),
            new Sonata\MediaBundle\SonataMediaBundle(),
            new CoopTilleuls\Bundle\CKEditorSonataMediaBundle\CoopTilleulsCKEditorSonataMediaBundle(),
            new Application\Sonata\MediaBundle\ApplicationSonataMediaBundle(),

//            // users
            new FOS\UserBundle\FOSUserBundle(),
            new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
            new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),
            new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
            new FOS\OAuthServerBundle\FOSOAuthServerBundle(),
            new Application\FOS\OAuthServerBundle\ApplicationFOSOAuthServerBundle(),
//            new HWI\Bundle\OAuthBundle\HWIOAuthBundle(),
//            new Xxx\Bundle\OAuthUserBundle\XxxOAuthUserBundle(),

            // rest api default
            new FOS\RestBundle\FOSRestBundle(),
            new JMS\SerializerBundle\JMSSerializerBundle(),
            new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
            new Application\FOS\RestBundle\ApplicationFOSRestBundle(),

            // form
            new Ivory\OrderedFormBundle\IvoryOrderedFormBundle(), //order fields with 'position' attribute

            //form types
            new Genemu\Bundle\FormBundle\GenemuFormBundle(),
            new Stnw\DatePickerBundle\StnwDatePickerBundle(),
            new Ivory\CKEditorBundle\IvoryCKEditorBundle(),
            new Misd\PhoneNumberBundle\MisdPhoneNumberBundle(),

            // charts
//            new Ob\HighchartsBundle\ObHighchartsBundle(),

            // grid
            new APY\DataGridBundle\APYDataGridBundle(),

//            new Lunetics\LocaleBundle\LuneticsLocaleBundle(),
            new JMS\I18nRoutingBundle\JMSI18nRoutingBundle(),
            new JMS\TranslationBundle\JMSTranslationBundle(),

            // project
            new Xxx\Bundle\AppBundle\XxxAppBundle(),
            new Xxx\Bundle\CompanyBundle\XxxCompanyBundle(),
            new Xxx\Bundle\TransactionBundle\XxxTransactionBundle(),
            new Xxx\Bundle\StoreBundle\XxxStoreBundle(),
            new Xxx\Bundle\DeviceBundle\XxxDeviceBundle(),
            new Xxx\Bundle\CatalogBundle\XxxCatalogBundle(),
            new Xxx\Bundle\ChipBundle\XxxChipBundle(),
            new Xxx\Bundle\CityBundle\XxxCityBundle(),
            new Xxx\Bundle\LastActivityBundle\XxxLastActivityBundle(),

            // frontend
            new WhiteOctober\BreadcrumbsBundle\WhiteOctoberBreadcrumbsBundle(),
            new Xxx\ContactBundle\XxxContactBundle(),
            new Application\Xxx\ContactBundle\ApplicationXxxContactBundle(),
            new Xxx\Bundle\FaqBundle\XxxFaqBundle(),
            new Xxx\Bundle\NewsBundle\XxxNewsBundle(),
            new Xxx\Bundle\MenuBundle\XxxMenuBundle(),
            new Xxx\Bundle\PageBundle\XxxPageBundle(),
            new Xxx\Bundle\SmsGatewayBundle\XxxSmsGatewayBundle(),
        ];

        if (in_array($this->getEnvironment(), ['dev', 'test'])) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();

            // translator, needed for grid
            $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
//            $bundles[] = new JMS\TranslationBundle\JMSTranslationBundle();
        }

        return $bundles;
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
    }
}
# app/config/config.yml
imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: ../../vendor/knplabs/doctrine-behaviors/config/orm-services.yml }

framework:
    #esi:             ~
    translator:      { fallback: "%locale%" }
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    templating:
        engines: ['twig']
        #assets_version: SomeVersionScheme
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        # handler_id set to null will use default session handler from php.ini
        handler_id:  ~
    fragments:       ~
    http_method_override: true

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"
    exception_controller: 'FOS\RestBundle\Controller\ExceptionController::showAction'
    form:
        resources:
            - 'StnwDatePickerBundle:Form:fields.html.twig'
            - 'XxxAppBundle:Form:fields.html.twig'
    globals:
        locales: "%locales%"

# Assetic Configuration
assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    bundles:        [ ]
    #java: /usr/bin/java
    filters:
        cssrewrite: ~
        #closure:
        #    jar: "%kernel.root_dir%/Resources/java/compiler.jar"
        #yui_css:
        #    jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"

# Doctrine Configuration
doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        types:
            json: Sonata\Doctrine\Types\JsonType
            phone_number: Misd\PhoneNumberBundle\Doctrine\DBAL\Types\PhoneNumberType
        # if using pdo_sqlite as your database driver, add the path in parameters.yml
        # e.g. database_path: "%kernel.root_dir%/data/data.db3"
        # path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true

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

sensio_framework_extra:
    view:
        annotations: false

fos_rest:
    param_fetcher_listener: true
    view:
        view_response_listener: 'force'
        formats:
            xml:  true
            json: true
        templating_formats:
            html: true
    format_listener:
        rules:
            - { path: ^/, priorities: [ html, json, xml ], fallback_format: ~, prefer_extension: true }
    exception:
        codes:
            'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
            'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
        messages:
            'Symfony\Component\Routing\Exception\ResourceNotFoundException': true
    allowed_methods_listener: true
    access_denied_listener:
        json: true
#    serializer:
#        serialize_null: true
    body_listener: true
    disable_csrf_role: ROLE_API

nelmio_api_doc:
    name: Xxx REST API
    sandbox:
        authentication:
            delivery: http
#            name:     apiKey
            type:     bearer         # `basic`, `bearer` are supported

sonata_block:
    default_contexts: [cms]
    blocks:
        # Enable the SonataAdminBundle block
        sonata.admin.block.admin_list:
            contexts:   [admin]
        sonata.admin.block.search_result:
            contexts:   [admin]

        # Your other blocks
        sonata.user.block.menu:    # used to display the menu in profile pages
        sonata.user.block.account: # used to display menu option (login option)

        sonata.block.service.text:
        sonata.block.service.action:
        sonata.block.service.rss:

sonata_admin:
    title:      Xxx
#    title_logo: bundles/acmedemo/img/fancy_acme_logo.png
    templates:
        # default global templates
        layout:  ApplicationSonataAdminBundle::layout.html.twig
        ajax:    SonataAdminBundle::ajax_layout.html.twig

        # default actions templates, should extend a global templates
        list:    SonataAdminBundle:CRUD:list.html.twig
        show:    SonataAdminBundle:CRUD:show.html.twig
        edit:    SonataAdminBundle:CRUD:edit.html.twig
        search:  SonataAdminBundle:Core:search.html.twig
        search_result_block: SonataAdminBundle:Block:block_search_result.html.twig

    dashboard:
        blocks:
            # display a dashboard block
            - { position: left, type: sonata.admin.block.admin_list }

        groups:
            default:

            fos_user:
                label: menu.group_users
                items: [sonata.user.admin.user, sonata.user.admin.group]

            xxx_company:
                label: menu.group_company
                items: [xxx.admin.company, xxx.admin.company_category, xxx.admin.store, xxx.admin.device]

            xxx_catalog:
                label: menu.group_catalog
                items: [xxx.admin.catalog.product, xxx.admin.catalog.product_category, xxx.admin.chip.rule]

            xxx_transaction:
                  label: menu.group_transaction
                  items: [xxx.admin.transaction]

            xxx_media:
                  label: menu.group_media
                  items: [sonata.media.admin.media]

            xxx_news:
                  label: menu.group_news
                  items: [xxx.news.admin.news]

            xxx_faq:
                  label: menu.group_faq
                  items: [xxx.faq.admin.faq]

            xxx_page:
                  label: menu.group_page
                  items: [xxx_page.admin.page]

            xxx_menu:
                  label: menu.group_menu
                  items: [xxx_menu.admin.menu, xxx_menu.admin.menu_type]

            xxx_city:
                  label: menu.group_city
                  items: [xxx_city.admin.city]

            xxx_sms_gateway:
                  label: menu.group_sms_gateway
                  items: [xxx_sms_gateway.admin.message]

    security:
        handler: sonata.admin.security.handler.role
            # acl security information
        information:
            ADMIN:    [MASTER]
        # permissions not related to an object instance and also to be available when objects do not exist
        # the DELETE admin permission means the user is allowed to batch delete objects
        admin_permissions: [CREATE, LIST, DELETE, UNDELETE, EXPORT, OPERATOR, MASTER]
        # permission related to the objects
        object_permissions: [VIEW, EDIT, DELETE, UNDELETE, OPERATOR, MASTER, OWNER]
    options:
        html5_validate: true # does not use html5 validation
        confirm_exit:   false # disable confirmation when quitting with unsaved changes
        use_select2:    true # disable select2
        pager_links:    5     # pager max links to display

    # set to true to persist filter settings per admin module in the user's session
    persist_filters: false

#read http://sonata-project.org/bundles/media/2-2/doc/reference/installation.html
sonata_media:
    # if you don't use default namespace configuration
    #class:
    #    media: MyVendor\MediaBundle\Entity\Media
    #    gallery: MyVendor\MediaBundle\Entity\Gallery
    #    gallery_has_media: MyVendor\MediaBundle\Entity\GalleryHasMedia
    default_context: default
    db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr

    contexts:
        default:  # the default context is mandatory
            providers:
#                - sonata.media.provider.dailymotion
                - sonata.media.provider.youtube
                - sonata.media.provider.image
#                - sonata.media.provider.file

            formats: ~
                small: { width: 100 , quality: 70}
                big:   { width: 500 , quality: 70}

    cdn:
        server:
            path: /uploads/media # http://media.sonata-project.org/

    filesystem:
        local:
            directory:  %kernel.root_dir%/../web/uploads/media
            create:     false

# Notice: EntityAudit currently only works with a DBAL Connection and EntityManager named "default".
simple_things_entity_audit:
    # таблицы мультиперевода автоматически НЕ цепляются, поэтому нужно указывать в ручную в этом списке
    audited_entities:
        - Application\Sonata\UserBundle\Entity\User
        - Application\Sonata\UserBundle\Entity\Group

    # If you need to exclude some entity properties from triggering a revision use:
#    global_ignore_columns:
#        - created_at
#        - updated_at

sonata_intl:
    timezone:
        default: Europe/Moscow
        detectors:
            - sonata.intl.timezone_detector.user
            - sonata.intl.timezone_detector.locale
        locales:
            ru:    Europe/Chisinau

fos_user:
    db_driver:      orm # can be orm or odm
    firewall_name:  admin
    user_class:     Application\Sonata\UserBundle\Entity\User
    from_email:
        address:        noreply@xxx.com
        sender_name:    Xxx Noreply
    registration:
        form:
            type:               application_sonata_user_registration
            handler:            fos_user.registration.form.handler.default
            name:               fos_user_registration_form
            validation_groups:  [XxxRegistration]
        confirmation:
            enabled:    true
            template:   ApplicationSonataUserBundle:Registration:email.txt.twig
    profile:
       form:
            type:               application_fos_user_profile
            handler:            fos_user.profile.form.handler.default
            name:               fos_user_profile_form
            validation_groups:  [Authentication]
    change_password:
        form:
            type:               application_fos_user_change_password
            handler:            fos_user.change_password.form.handler.default
            name:               fos_user_change_password_form
            validation_groups:  [ChangePassword, Default]
    group:
        group_class:   Application\Sonata\UserBundle\Entity\Group
        group_manager: sonata.user.orm.group_manager                    # If you're using doctrine orm

    service:
        user_manager: sonata.user.orm.user_manager                      # If you're using doctrine orm
        mailer: fos_user.mailer.twig_swift

sonata_user:
    security_acl:     false
    class:
        user:         Application\Sonata\UserBundle\Entity\User
        group:        Application\Sonata\UserBundle\Entity\Group

    profile:  # Profile Form (firstname, lastname, etc ...)
        form:
            type:               application_sonata_user_profile
            handler:            sonata_user.form.handler.profile
            name:               sonata_user_profile_form
            validation_groups:  [Profile]
    impersonating:
        route:              sonata_admin_dashboard

parameters:
    sonata.user.admin.user.class: Application\Sonata\UserBundle\Admin\UserAdmin
    knp.doctrine_behaviors.blameable_listener.user_entity: Application\Sonata\UserBundle\Admin\UserAdmin
#    sonata.user.admin.user.translation_xxxin: ApplicationUserBundle

fos_oauth_server:
    db_driver: orm       # Driver availables: orm, mongodb, or propel
    client_class:        Application\FOS\OAuthServerBundle\Entity\Client
    access_token_class:  Application\FOS\OAuthServerBundle\Entity\AccessToken
    refresh_token_class: Application\FOS\OAuthServerBundle\Entity\RefreshToken
    auth_code_class:     Application\FOS\OAuthServerBundle\Entity\AuthCode
    service:
        user_provider: fos_user.user_manager
        options:
            access_token_lifetime: 3600 #seconds
            token_type: Bearer
#            supported_scopes: oauth_scope_scanner test1

fos_js_routing:
    cache_control:
        # All are optional, defaults shown
        public: false   # can be true (public) or false (private)
        maxage: null    # integer value, e.g. 300
        smaxage: null   # integer value, e.g. 300
        expires: null   # anything that can be fed to "new \DateTime($expires)", e.g. "5 minutes"
        vary: []        # string or array, e.g. "Cookie" or [ Cookie, Accept ]

jms_serializer:
    metadata:
        auto_detection: true
        directories:
            SonataUserBundle:
                namespace_prefix: "Sonata\\UserBundle"
                path: "@ApplicationSonataUserBundle/Resources/config/serializer/SonataUserBundle"
            FOSUserBundle:
                namespace_prefix: "FOS\\UserBundle"
                path: "@ApplicationSonataUserBundle/Resources/config/serializer/FOSUserBundle/"

white_october_pagerfanta:
    exceptions_strategy:
        out_of_range_page:        to_http_not_found
        not_valid_current_page:   to_http_not_found

apy_data_grid:
    limits: [20, 50, 100]
    pagerfanta:
        enable: true    #default false
        view_class: Pagerfanta\View\TwitterBootstrap3View #default    Pagerfanta\View\DefaultView
        options:            #all options of pager fanta view constructor
           prev_message : «
           next_message : »

genemu_form:
    date: ~
    captcha: ~
#    tinymce: ~

a2lix_translation_form:
    locales: %locales%       # [1]
    required_locales: %locales%      # [2]
    manager_registry: doctrine      # [3]
    templating: "A2lixTranslationFormBundle::default.html.twig"      # [4]

white_october_breadcrumbs:
    viewTemplate:       "XxxAppBundle:Breadcrumbs:breadcrumbs.html.twig"
    separator:          ""

ivory_ck_editor:
    default_config: default
    configs:
        default:
            filebrowserBrowseRoute: admin_sonata_media_media_browser
            filebrowserImageBrowseRoute: admin_sonata_media_media_browser
            # Display images by default when clicking the image dialog browse button
            filebrowserImageBrowseRouteParameters:
                provider: sonata.media.provider.image
            filebrowserUploadRoute: admin_sonata_media_media_upload
            filebrowserUploadRouteParameters:
                provider: sonata.media.provider.file
            # Upload file as image when sending a file from the image dialog
            filebrowserImageUploadRoute: admin_sonata_media_media_upload
            filebrowserImageUploadRouteParameters:
                provider: sonata.media.provider.image
                context: my-context # Optional, to upload in a custom context

xxx_transaction:
    sms_confirmation: %transaction_sms_confirmation%

xxx_contact:
    store_data:            false
    contact_class:         Xxx\ContactBundle\Model\BaseContact

    form:
        type:              application_xxx_contact
#        handler:           xxx_contact.form.handler.default
#        name:              contact_form
#        validation_groups: [Default]
#        subject_provider:  xxx_contact.subject_provider.noop
        captcha_type:      genemu_captcha
#
    email:
#        mailer:            xxx_contact.mailer.twig_swift
        recipient_address: "%admin_email%" # Required
#        template:          XxxContactBundle:Contact:email.txt.twig

jms_i18n_routing:
    default_locale: %locale%
    locales: %locales%
    strategy: prefix_except_default

xxx_sms_gateway:
    monolog_handler: monolog.logger.sms_gateway
    message:
        class: Xxx\Bundle\SmsGatewayBundle\Entity\Message
        manager: xxx_sms_gateway.entity.message_manager
    default_gateway: bulk_sms
    gateways:
        bulk_sms:
            sender: %sms_gateway_bulk_sms_sender%
            username: %sms_gateway_bulk_sms_username%
            password: %sms_gateway_bulk_sms_password%
            mode:
                charset: plaintext # plaintext, utf8, windows-1251
                max_number_of_chars: 160 # 160 for plaintext, 70 for UTF8 and Windows 1251
#                base_url: http://79.170.224.75/BulkSMSAPI/UnifunBulkSMSAPI.asmx/SendSMSNoneDigitsEncoded
                base_url: http://79.170.224.75/BulkSMSAPI/UnifunBulkSMSAPI.asmx/SendSMSSimple
            report:
                enabled: false
                mask: 31 # 1, 2, 4, 8, 16, 31
                route: xxx_sms_gateway_sms_report_bulk_sms

bazinga_js_translation:
    locale_fallback: %locale%
    active_locales: %locales%
    default_xxxin: XxxAppBundle

xxx_last_activity:
    audited_entities:
#        - Application\Sonata\UserBundle\Entity\User # при регистарции нет имени
        - Xxx\Bundle\CompanyBundle\Entity\Company
        - Xxx\Bundle\FaqBundle\Entity\Faq
        - Xxx\Bundle\NewsBundle\Entity\News

Standart pagination with pagerfanta

{% if pagination.haveToPaginate %}
    {{ pagerfanta(pagination, 'twitter_bootstrap3_translated') }}
{% endif %}

Standart pagination call

// return some query
$query = $this->getManager()->getQueryAllByCategory($findCompaniesByCategory); 
$page = $request->query->get('page', 1);

$pagination = new Pagerfanta(new DoctrineORMAdapter($query));
$pagination
    ->setMaxPerPage($this->container->getParameter('items_on_page'))
    ->setCurrentPage($page)
;
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?