优化url,多应用之间不能互相根据路由生成url,没有研究透

This commit is contained in:
augushong
2020-08-15 00:08:16 +08:00
parent 5ad73e5540
commit 45f8a09b1c
9 changed files with 24 additions and 11 deletions

View File

@@ -9,6 +9,7 @@ use app\model\Post as ModelPost;
use app\model\PostCategory;
use app\model\PostTag;
use app\model\Tag;
use think\facade\Route;
use think\facade\View;
use think\Request;
@@ -56,6 +57,8 @@ class Post extends Common
//
$post_data = $request->post();
$post_data['uid'] = uniqid();
$categorys = [];
$tags = [];
if (isset($post_data['categorys'])) {

View File

@@ -0,0 +1,2 @@
<?php
use think\facade\Route;

View File

@@ -6,6 +6,7 @@ use app\model\Category;
use app\model\Nav;
use app\model\Post;
use app\model\PostCategory;
use think\facade\Route;
use think\facade\View;
use think\Request;
@@ -19,8 +20,6 @@ class Index extends Common
public function index()
{
//
$sub_category = [];
if(!empty($this->request->param('category_id'))){

View File

@@ -47,11 +47,11 @@ class Post extends Common
* @param int $id
* @return \think\Response
*/
public function read($id)
public function read($uid)
{
//
$model_post = ModelPost::find($id);
$model_post = ModelPost::where('uid',$uid)->find();
$model_post->hits = $model_post->hits + 1;

View File

@@ -0,0 +1,7 @@
<?php
use think\facade\Route;
Route::rule('a:uid', 'Post/read');
Route::rule('i[:category_id]/s[:sub_category_id]/p[:page]', 'Index/index');

View File

@@ -136,4 +136,11 @@ class Post extends Model
return get_source_link($value);
}
public function getReadUrlAttr()
{
$url_info = parse_url((string)url('index/Index/index')->domain('www'));
return $url_info['scheme'].'://'.$url_info['host'].'/a'.$this->getData('uid').'.html';
}
}