panychek/zf-device-detector

利用 DeviceDetector 库的 ZF3 模块

0.1.1 2019-07-26 20:51 UTC

This package is not auto-updated.

Last update: 2024-09-30 15:16:02 UTC


README

使用 DeviceDetector 库为您的 MVC 应用程序提供设备检测支持的 ZF3 模块。

安装

通过 Composer 安装模块

composer require panychek/zf-device-detector

然后将模块名称添加到项目配置文件 config/application.config.php 中的 modules 键下

return [
    'modules' => [
        // ...
        'ZfDeviceDetector',
    ],
    // ...
];

使用方法

此模块在您的应用程序服务管理器中注册了一个新的服务,该服务可在 DeviceDetector::class 键下使用。该服务提供了一个实际的 DeviceDetector 实例,该实例使用内置的 Request 服务获取的用户代理进行初始化。

该模块还提供了一种视图助手和控制器插件,可代理对该实例的所有调用。

有关支持功能的更多信息,请参阅 库文档

服务

在您的 factories 中使用

$deviceDetector = $container->get(DeviceDetector::class);
$client = $deviceDetector->getClient();

视图助手

在您的 view templates 中使用

$client = $this->deviceDetector()->getClient();

控制器插件

在您的 controllers 中使用

$client = $this->deviceDetector()->getClient();