第一步:后台增加控制开关 url_on
第二步: routeroute_cms.php 修改 路由
Route::rule('lists/:catid/[:condition]', 'cms/index/lists')->pattern(['catid' => 'd+', 'condition' => '[0-9_&=a-zA-Z]+']);
Route::rule('shows/:catid/:id', 'cms/index/shows')->pattern(['catid' => 'd+', 'id' => 'd+']);替换如下
$url_on = Db::name('config')->where('name','url_on')->cache(3600)->value('value');
if($url_on == 1){
Route::rule('/:catid/:id', 'cms/index/shows')->pattern(['catid' => '[d|w/]+', 'id' => 'd+'])->before(['appcmsbehaviorShowInfo']);
Route::rule(':catid/[:condition]', 'cms/index/lists')->pattern(['catid' => '[d|w/]+', 'condition' => '[0-9_&=a-zA-Z]+'])->before(['appcmsbehaviorCategoryInfo']);
}else{
Route::rule('lists/:catid/[:condition]', 'cms/index/lists')->pattern(['catid' => 'd+', 'condition' => '[0-9_&=a-zA-Z]+']);
Route::rule('shows/:catid/:id', 'cms/index/shows')->pattern(['catid' => 'd+', 'id' => 'd+']);
}
第三步: 修改applicationcmsfunction.php
buildContentUrl方法改为如下
//创建内容链接
function buildContentUrl($catid, $id, $suffix = true, $domain = false)
{
$url_on = Db::name('config')->where('name','url_on')->value('value');
if($url_on == 1){
$catdir = Db::name('category')->where('id',$catid)->value('catdir');
return url('cms/index/shows', ['catid' => $catdir, 'id' => $id], $suffix, $domain);
}else{
return url('cms/index/shows', ['catid' => $catid, 'id' => $id], $suffix, $domain);
}
}第四步: 修改applicationcmscontrollerIndex.php
内容 shows()方法修改
$catid = $this->request->param('catid/d', 0);替换
$catid = $this->request->param('catid/s', 0);$category = getCategory($catid);
替换为
if (config('url_on') == 1) // winner.zyy 栏目判断 20-11-17
{
$category = getCategoryByName($catid);
$catid = $category['id'];
}
else
{
$category = getCategory($catid);
}$modelInfo = cache('Model')[$modelid];下方加入判断
if (!is_numeric($id)) // winner.zyy 栏目判断 20-11-17
{
$id = Db::name($modelInfo['tablename'])->where('subtitle', $id)->value("id");
}内容 lists()方法修改
$catid = $this->request->param('catid/d', 0);替换
$catid = $this->request->param('catid/s', 0);继续找到
$category = getCategory($catid);
替换为
if (config('url_on') == 1)
{
$category = getCategoryByName($catid);
$catid = $category['id'];
}else{
$category = getCategory($catid);
}继续找到
$modelInfo = cache('Model')[$modelid];替换为
if (!is_numeric($id))
{
$id = Db::name($modelInfo['tablename'])->where('subtitle', $id)->value("id");
}第五步:
applicationcmsbehavior 目录下创建ShowInfo.php
代码如下:
<?php
namespace appcmsbehavior;
use appcmsmodelCategory as CategoryModel;
use appcommoncontrollerAdminbase;
use thinkDb;
class ReadInfo
{
public function run()
{
$w_url = explode("/",request()->url());
$url_on = Db::name('category')->where('catdir',$w_url['1'])->find();
if(!$url_on){
return false;
}
}
}第六步:
applicationcmsbehavior 目录下创建CategoryInfo.php
代码如下:
<?php
namespace appcmsbehavior;
use appcmsmodelCategory as CategoryModel;
use appcommoncontrollerAdminbase;
use thinkDb;
class CategoryInfo
{
public function run()
{
$request_url = explode("/",request()->url());
$w_url = str_replace(".html","",$request_url['1']);
$url_on = Db::name('category')->where('catdir',$w_url)->find();
$url = $url_on['catdir'].".html";
if($url !== $request_url['1']){
return false;
}
}
}完成 记得开关
