erosdelalamo / yii2-url-shortener
用于处理自定义缩短URL的扩展
1.0.0
2023-02-01 16:04 UTC
Requires
- yiisoft/yii2: ^2.0@dev
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