前端虚拟页路由机制详解📅 2024-06-30  |  👁 549 次浏览

DaoKeCMS插件可以注册前端虚拟页面,通过?mod={slug}或?mod={slug}_{action}访问。

路由注册

// main.php 中
if (req('mod') === 'download') {
    // 渲染下载列表页
    $items = myplugin_get_downloads();
    include template_path('download.php');
    exit;
}

if (req('mod') === 'downdetail') {
    // 渲染下载详情页
    $id = intval2(get('id', 0));
    $item = myplugin_get_download($id);
    include template_path('downdetail.php');
    exit;
}
  • 通过req('mod')判断路由
  • 渲染后exit终止后续执行
  • 模板文件优先用template_path()定位
  • 插件可自带兜底页面模板不存在时使用

芒阳网络团域cms开发中心

Copyright © 2023 刀客CMS内容管理系统