71 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
			
		
		
	
	
			71 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
<?php
 | 
						|
// +----------------------------------------------------------------------
 | 
						|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
 | 
						|
// +----------------------------------------------------------------------
 | 
						|
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
 | 
						|
// +----------------------------------------------------------------------
 | 
						|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
 | 
						|
// +----------------------------------------------------------------------
 | 
						|
// | Author: liu21st <liu21st@gmail.com>
 | 
						|
// +----------------------------------------------------------------------
 | 
						|
use think\facade\Route;
 | 
						|
use think\facade\Cache;
 | 
						|
use app\model\Category;
 | 
						|
use app\model\Model as MModel;
 | 
						|
 | 
						|
Route::get('/', 'index/index');
 | 
						|
 | 
						|
 | 
						|
Route::get('/article/detail/:id', "article/detail")->pattern(['id' => '\d+']);
 | 
						|
Route::get('article', "article/index");
 | 
						|
Route::get('position/:id', "position/detail")->pattern(['id' => '\d+']);
 | 
						|
Route::get('/activity/:id', "article/detail")->pattern(['id' => '\d+']);
 | 
						|
Route::get('/news/:id', "article/detail")->pattern(['id' => '\d+']);
 | 
						|
Route::get('/service/:id', "article/detail")->pattern(['id' => '\d+']);
 | 
						|
Route::get('/product/detail/:id', "product/detail")->pattern(['id' => '\d+']);
 | 
						|
Route::rule('articles/ajaxlist', 'article/ajaxList', 'GET|POST');
 | 
						|
Route::get('articles/:category_id', "article/index");
 | 
						|
 | 
						|
// 验证码
 | 
						|
Route::get('captcha/code', "\\think\\captcha\\CaptchaController@index");
 | 
						|
// 验证码
 | 
						|
Route::get('captcha/[:id]', "\\think\\captcha\\CaptchaController@index");
 | 
						|
// 友情链接页
 | 
						|
Route::get('friendship', "links/index");
 | 
						|
 | 
						|
// 文件下载
 | 
						|
Route::get('download/file', "download/file");
 | 
						|
 | 
						|
Route::get('search', "search/index");
 | 
						|
 | 
						|
// 栏目动态路由规则绑定
 | 
						|
if(Cache::has("categoryNames")){
 | 
						|
    $categoryNames = Cache::get("categoryNames");
 | 
						|
}else{
 | 
						|
    $categoryNames = Category::getRouteList();
 | 
						|
    Cache::set("categoryNames",$categoryNames,86400);
 | 
						|
}
 | 
						|
 | 
						|
foreach ($categoryNames as $item) {
 | 
						|
    //路由别名入口
 | 
						|
    if ($item["model_id"] == MModel:: MODEL_ARTICLE) {
 | 
						|
        Route::get($item['route'] . "$", "article/index")->append(['categoryId' => $item['id']]);
 | 
						|
        //文章的
 | 
						|
        Route::get($item['route'] . '/:id', "article/detail")->pattern(['id' => '\d+']); //articleId 只匹配非负整数
 | 
						|
    }
 | 
						|
    else if ($item["model_id"] == MModel:: MODEL_PRODUCT) {
 | 
						|
        Route::get($item['route'] . "$", "product/index")->append(['categoryId' => $item['id']]);
 | 
						|
        //文章的
 | 
						|
        Route::get($item['route'] . '/:id', "product/detail")->pattern(['id' => '\d+']); //id' 只匹配非负整数
 | 
						|
    }else {
 | 
						|
        Route::get($item['route'] . "$", "page/index")->append(['categoryId' => $item['id']]);
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
// 异常页面
 | 
						|
Route::get('/404', "error/notFind");
 | 
						|
Route::get('/500', "error/serviceFail");
 | 
						|
Route::get('error/404', "error/notFind");
 | 
						|
Route::get('error/500', "error/serviceFail");
 |