erosdelalamo/yii2-url-shortener

用于处理自定义缩短URL的扩展

安装数量: 1,592

依赖: 0

建议者: 0

安全性: 0

星星: 2

关注者: 2

分支: 2

开放问题: 1

类型:yii2-extension

1.0.0 2023-02-01 16:04 UTC

This package is auto-updated.

Last update: 2024-09-11 23:48:56 UTC


README

Do not get fooled by the age of changes made to library. It works like the first day, and that is why it has not been updated

在您的yii2应用程序中创建短链接。甚至可以为缩短的URL定义一个过期日期。请参阅此README文件了解如何操作。

安装

将模块添加到您的配置文件中

首先:运行@vendor/eseperio/yii2-url-shortener/src/migrations中包含的迁移。

  //...

'modules' => [
     'shortener' => [
            'class' => \eseperio\shortener\ShortenerModule::class
        ]
  ]

  //...

将引导类添加到您的引导配置中。

'basePath' => dirname(__DIR__),
    'bootstrap' => [
        'log',
        \eseperio\shortener\Bootstrap::class,
    ],

    'aliases' => [
    //...

使用方法

创建短链接

Yii::$app->getModule('shortener')->short('http://original.url/goes/here')

// An array can be provided too.

Yii::$app->getModule('shortener')->short(['controller/action','param' => 'value'])

可以设置一个生命周期。链接将在该日期后停止工作。

Yii::$app->getModule('shortener')->short($url, 3600)

展开链接

Yii::$app->getModule('shortener')->expand('link id')

重定向

模块包含一个控制器来处理重定向。要使其工作,您需要创建一个指向您应用程序域的链接,后跟URL的短ID。

http://myapp.tld/gGyU