teckhouse/mdetect-bundle

Symfony2 移动设备检测包(MDetect 包装器)

安装: 208

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 0

开放问题: 0

类型:symfony-bundle

dev-master 2013-10-03 17:46 UTC

This package is not auto-updated.

Last update: 2024-09-23 13:47:12 UTC


README

在您的 composer.json 中添加 TeckHouseMDetectBundle

{
    "require": {
        "teckhouse/mdetect-bundle": "dev-master"
    }
}

使用 composer 安装包

$ php composer.phar update teckhouse/mdetect-bundle

启用包

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        
        // Yours bundles
        // [...] 

        // Mobile Detect Bundle
        new TeckHouse\MDetectBundle\TeckHouseMDetectBundle(),
    );
}

配置

只有一个参数 :)

在 config.yml 中

teckhouse_mdetect:
    inject_value: [ true | false ]

使用方法

如果请求注入设置为 true,您将在请求参数中找到 var "$userDeviceType",该变量用于识别设备类型:“mobile”,“tablet”,“desk”。

要获取值,请执行以下操作

$request->server->get("userDeviceType");

如果注入设置为 "off",您可以使用服务获取有关设备的详细信息

$this->get('teckhouse_mdetect.wrapper');

在任何情况下,您都可以使用 Twig 过滤器扩展在模板中检索状态

{{ getDeviceType() }}