【独立版】定义自己的短链系统
打开站点根目录application/index/controller/Index.php复制如下代码:
<?php
namespace app\index\controller;
use app\common\controller\Frontend;
use app\admin\model\nianbao\Shortlink;
class Index extends Frontend
{
protected $noNeedLogin = '*';
protected $noNeedRight = '*';
protected $layout = '';
public function index()
{
header("Location:".request()->root(true).'/XasZQxTAdm.php');
}
/**
* 短链
*/
public function shortlink()
{
$name = $this->request->param('name');
$shortlink = Shortlink::get(['querycode'=>$name]);
if (empty($shortlink)) {
$this->error('短链不存在');
}
// 更新短链访问次数
$shortlink->allowField(true)->save(['visits'=>$shortlink->visits]);
header("Location:".$this->request->root(true).'/h5/pages/business/shortlink?id='.$shortlink->id);
}
}
最终效果如下图所示:
注意红框内的就是需要修改的地方,图里的第一个红框中map应该是nianbao,按照上方代码复制粘贴就行。
页:
[1]