yan/device-detector-bundle

Symfony2 扩展包,用于检测设备和将它们导向正确的控制器。

v1.0.2 2016-02-11 10:45 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:05:11 UTC


README

Symfony2 扩展包,用于切换不同设备视图的控制器。此扩展包适用于具有两种不同控制器(移动端和桌面端)的响应式网站。

示例配置

1. 简单的桌面到移动端控制器重定向。

这将同时为平板电脑渲染移动端视图。

device_detector:
    mobile:
        enabled: true
        controllers:
            -
                from_controller_path: 'Acme\MainBundle\Controller\Frontend'
                to_controller_path: 'Acme\MainBundle\Controller\MobileFrontend'
                routes:
                    - 'acme_frontend_homepage'
                    - 'acme_frontend_news'
                    - 'acme_frontend_about_us'

2. 简单的桌面到移动端重定向,但为平板电脑渲染桌面端视图。

device_detector:
    tablet:
        treat_as_mobile: false
        controllers: []
    mobile:
        enabled: true
        controllers:
            -
                from_controller_path: 'Acme\MainBundle\Controller\Frontend'
                to_controller_path: 'Acme\MainBundle\Controller\MobileFrontend'
                routes:
                    - 'acme_frontend_homepage'
                    - 'acme_frontend_news'
                    - 'acme_frontend_about_us'

3. 简单的桌面到平板电脑控制器重定向。

默认情况下,扩展包将平板电脑视为移动设备,并遵循移动端重定向的配置,因此当启用平板电脑重定向时,需要将 treat_as_mobile 设置为 false。

device_detector:
    tablet:
        enabled: true
        treat_as_mobile: false
        controllers:
            -
                from_controller_path: 'Acme\MainBundle\Controller\Frontend'
                to_controller_path: 'Acme\MainBundle\Controller\TabletFrontend'
                routes:
                    - 'acme_frontend_homepage'
                    - 'acme_frontend_news'
                    - 'acme_frontend_about_us'
    mobile:
        enabled: true
        controllers:
            -
                from_controller_path: 'Acme\MainBundle\Controller\Frontend'
                to_controller_path: 'Acme\MainBundle\Controller\MobileFrontend'
                routes:
                    - 'acme_frontend_homepage'
                    - 'acme_frontend_news'
                    - 'acme_frontend_about_us'

4. 设置可选的移动端视图。

提供了一个选项,可以通过设置一个cookie来可选地渲染移动端页面。如果设置了此cookie,则将覆盖重定向并渲染桌面端版本,直到cookie过期。

device_detector:
    override_cookie: 'DEVICE_DETECTOR_OVERRIDE'
    tablet:
        enabled: true
        treat_as_mobile: false
        controllers:
            -
                from_controller_path: 'Acme\MainBundle\Controller\Frontend'
                to_controller_path: 'Acme\MainBundle\Controller\TabletFrontend'
                routes:
                    - 'acme_frontend_homepage'
                    - 'acme_frontend_news'
                    - 'acme_frontend_about_us'
    mobile:
        enabled: true
        controllers:
            -
                from_controller_path: 'Acme\MainBundle\Controller\Frontend'
                to_controller_path: 'Acme\MainBundle\Controller\MobileFrontend'
                routes:
                    - 'acme_frontend_homepage'
                    - 'acme_frontend_news'
                    - 'acme_frontend_about_us'