david221189av / mobile-detect-bundle
Symfony 3.4-6.x 扩展包,用于检测移动设备,管理移动视图并重定向到移动和平板版。
dev-main
2023-12-05 11:59 UTC
Requires
- php: >=8.2.9
- mobiledetect/mobiledetectlib: ^4.8.04
- symfony/dependency-injection: ^7.0
- symfony/event-dispatcher: ^7.0
- symfony/framework-bundle: ^7.0
- symfony/yaml: ^7.0
- twig/twig: ^3.8
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.40
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.10
- phpstan/phpstan-nette: ^1.2
- phpstan/phpstan-phpunit: ^1.3
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.7
- symfony/dotenv: ^7.0
- symfony/phpunit-bridge: ^7.0
This package is auto-updated.
Last update: 2024-09-06 11:08:25 UTC
README
MobileDetectBundle
Symfony 3.4.x-6.0.x 扩展包,用于检测移动设备,管理移动视图并重定向到移动和平板版。
此扩展包是 suncat2000/MobileDetectBundle 的分支。由于该项目似乎不再维护,我们决定创建并维护一个分支。有关更多信息,请参阅我们的 清单。
简介
此扩展包使用 Mobile_Detect 类并提供以下功能
- 通过名称、操作系统、浏览器用户代理检测各种移动设备
- 管理各种移动设备的网站视图(
mobile
、tablet
、full
) - 重定向到移动和平板网站
文档
安装
composer require tattali/mobile-detect-bundle
使用 Symfony 旧版本安装:[此处](https://github.com/david221189av/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}
进一步了解
贡献和反馈
任何反馈和贡献都将非常感激。
许可和致谢
此扩展包受 MIT 许可证的保护。请参阅扩展包中的完整 许可证。
原作者:suncat2000、HenriVesala、netmikey 以及 所有贡献者