xpanel/mobile-detect-bundle

Symfony 7 扩展包,用于检测移动设备,管理移动视图并重定向到移动和平板版。

安装次数: 56

依赖者: 0

建议者: 0

安全: 0

星标: 1

关注者: 0

分支: 153

类型:symfony-bundle

dev-main 2023-12-06 15:15 UTC

This package is auto-updated.

Last update: 2024-09-06 17:27:04 UTC


README

Mobile Detect

MobileDetectBundle

Symfony 7 扩展包,用于检测移动设备,管理移动视图并重定向到移动和平板版。

Github Actions Status Latest Stable Version Total Downloads codecov License PHP Version Require

此扩展包是基于suncat2000/MobileDetectBundle的分支。由于该项目似乎已不再维护,我们决定创建并维护一个分支。更多信息请参阅我们的manifest

简介

此扩展包使用Mobile_Detect类,并提供以下功能:

  • 通过名称、操作系统、浏览器User-Agent检测各种移动设备
  • 管理各种移动设备的网站视图(mobiletabletfull
  • 重定向到移动和平板网站

文档

安装

composer require tattali/mobile-detect-bundle

使用 Symfony 旧版本安装:[这里](https://github.com/xpanel/MobileDetectBundle/blob/HEAD/src/Resources/doc/legacy-versions.md)

用法

检查设备

use MobileDetectBundle\DeviceDetector\MobileDetectorInterface;

public function someaction(MobileDetectorInterface $mobileDetector)
{
    $mobileDetector->isMobile();
    $mobileDetector->isTablet();
    $mobileDetector->is('iPhone');
}

使用 Twig

{% if is_mobile() %}
{% if is_tablet() %}
{% if is_device('iPhone') %} # magic methods is[...]

切换设备视图

要切换设备视图,请使用 device_view GET 参数

https://:8000?device_view={full/mobile/tablet}

或使用 Symfony 工具栏 mbd-bundle-sf-toolbar

进一步了解

贡献和反馈

任何反馈和贡献都将非常受欢迎。

许可和致谢

此扩展包采用 MIT 许可证。请参阅扩展包中的完整许可证

原作者:suncat2000HenriVesalanetmikey 以及所有贡献者