首页>建站相关>Typecho默认路由表一览

Typecho默认路由表一览

路由器(Route)

路由器(Route)是Typecho系统中的一个重要组件,类似mod_rewrite的机制,来实现独立的URL和指定的controller/action/params的映射规则.它通过识别诸如http://localhost/2008/10/1/hello-world此类的伪地址,它在文件系统中并不存在但通过结合rewrite我们可以模拟出这样一个静态地址,路由器在路由表中找到匹配记录,并将用户请求导向最终应答页面.

通过这个机制,Typecho可以拥有简洁且可配置的URL并且可以摆脱对mod_rewrite的依赖.在一般的系统中,都会有一个朴素的路由系统,它们通过识别GET中的默认参数值来达到导向的目的.而在Typecho中我们通过匹配系统的伪路径来导向目的,路由表是可以配置的,并且可以动态地增加.路由基类在includes/Route.php里面.

相关变量:

$current:当前路由名称. $_parameters:数组,路径解析值列表.

相关函数:

target($path):路由指向函数,返回根据pathinfo和路由表配置的目的文件名.$path为目的文件所在目录. getParameter($key):获取路径解析值. parse($name, array $value = NULL, $prefix = NULL):路由反解析.$name为路由配置表名称,$value为路由填充值,默认为空,$prefix为最终合成路径的前缀,默认为空.

[index] => Array ( 
  [url] => / 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^[/]?$| 
  [format] => / 
  [params] => Array ( ) 
) 
[archive] => Array ( 
  [url] => /blog/ 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/blog[/]?$| 
  [format] => /blog/ 
  [params] => Array ( ) 
) 
[do] => Array ( 
  [url] => /action/[action:alpha] 
  [widget] => Widget_Do 
  [action] => action [regx] => |^/action/([_0-9a-zA-Z-]+)[/]?$| 
  [format] => /action/%s 
  [params] => Array ( [0] => action ) 
) 
[post] => Array ( 
  [url] => /[slug].html 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/([^/]+)\.html[/]?$| 
  [format] => /%s.html 
  [params] => Array ( [0] => slug ) 
) 
[attachment] => Array (
  [url] => /attachment/[cid:digital]/ 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/attachment/([0-9]+)[/]?$| 
  [format] => /attachment/%s/ 
  [params] => Array ( [0] => cid ) 
) 
[category] => Array ( 
  [url] => /[slug]/ 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/([^/]+)[/]?$| [format] => /%s/ 
  [params] => Array ( [0] => slug ) 
) 
[tag] => Array ( 
  [url] => /tag/[slug]/ 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/tag/([^/]+)[/]?$| 
  [format] => /tag/%s/ [params] => Array ( [0] => slug ) 
) 
[author] => Array ( 
  [url] => /author/[uid:digital]/ 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/author/([0-9]+)[/]?$| 
  [format] => /author/%s/ 
  [params] => Array ( [0] => uid ) 
) 
[search] => Array ( 
  [url] => /search/[keywords]/ 
  [widget] => Widget_Archive 
  [action] => render [regx] => |^/search/([^/]+)[/]?$| 
  [format] => /search/%s/ 
  [params] => Array ( [0] => keywords ) 
) 
[index_page] => Array ( 
  [url] => /page/[page:digital]/ 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/page/([0-9]+)[/]?$| 
  [format] => /page/%s/ 
  [params] => Array ( [0] => page ) 
) 
[archive_page] => Array ( 
  [url] => /blog/page/[page:digital]/ 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/blog/page/([0-9]+)[/]?$| 
  [format] => /blog/page/%s/ 
  [params] => Array ( [0] => page ) 
) 
[category_page] => Array ( 
  [url] => /[slug]/[page:digital]/ 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/([^/]+)/([0-9]+)[/]?$| 
  [format] => /%s/%s/ 
  [params] => Array ( [0] => slug [1] => page ) 
) 
[tag_page] => Array ( 
  [url] => /tag/[slug]/[page:digital]/ 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/tag/([^/]+)/([0-9]+)[/]?$| 
  [format] => /tag/%s/%s/ 
  [params] => Array ( [0] => slug [1] => page ) 
) 
[author_page] => Array ( 
  [url] => /author/[uid:digital]/[page:digital]/ 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/author/([0-9]+)/([0-9]+)[/]?$| 
  [format] => /author/%s/%s/ 
  [params] => Array ( [0] => uid [1] => page ) 
) 
[search_page] => Array ( 
  [url] => /search/[keywords]/[page:digital]/ 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/search/([^/]+)/([0-9]+)[/]?$| 
  [format] => /search/%s/%s/ 
  [params] => Array ( [0] => keywords [1] => page ) 
) 
[archive_year] => Array ( 
  [url] => /[year:digital:4]/ 
  [widget] => Widget_Archive [action] => render 
  [regx] => |^/([0-9]{4})[/]?$| 
  [format] => /%s/ 
  [params] => Array ( [0] => year ) 
) 
[archive_month] => Array ( 
  [url] => /[year:digital:4]/[month:digital:2]/ 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/([0-9]{4})/([0-9]{2})[/]?$| 
  [format] => /%s/%s/ 
  [params] => Array ( [0] => year [1] => month ) 
) 
[archive_day] => Array ( 
  [url] => /[year:digital:4]/[month:digital:2]/[day:digital:2]/ 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/([0-9]{4})/([0-9]{2})/([0-9]{2})[/]?$| 
  [format] => /%s/%s/%s/ 
  [params] => Array ( [0] => year [1] => month [2] => day ) 
) 
[archive_year_page] => Array ( 
  [url] => /[year:digital:4]/page/[page:digital]/ 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/([0-9]{4})/page/([0-9]+)[/]?$| 
  [format] => /%s/page/%s/ 
  [params] => Array ( [0] => year [1] => page ) 
) 
[archive_month_page] => Array ( 
  [url] => /[year:digital:4]/[month:digital:2]/page/[page:digital]/ 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/([0-9]{4})/([0-9]{2})/page/([0-9]+)[/]?$| 
  [format] => /%s/%s/page/%s/ 
  [params] => Array ( [0] => year [1] => month [2] => page ) 
) 
[archive_day_page] => Array ( 
  [url] => /[year:digital:4]/[month:digital:2]/[day:digital:2]/page/[page:digital]/ 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/([0-9]{4})/([0-9]{2})/([0-9]{2})/page/([0-9]+)[/]?$| 
  [format] => /%s/%s/%s/page/%s/ 
  [params] => Array ( [0] => year [1] => month [2] => day [3] => page ) 
) 
[comment_page] => Array ( 
  [url] => [permalink:string]/comment-page-[commentPage:digital] 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^(.+)/comment\-page\-([0-9]+)[/]?$|
  [format] => %s/comment-page-%s 
  [params] => Array ( [0] => permalink [1] => commentPage ) 
) 
[feed] => Array ( 
  [url] => /feed[feed:string:0] 
  [widget] => Widget_Archive 
  [action] => feed 
  [regx] => |^/feed(.*)[/]?$| 
  [format] => /feed%s 
  [params] => Array ( [0] => feed ) 
) 
[feedback] => Array ( 
  [url] => [permalink:string]/[type:alpha] 
  [widget] => Widget_Feedback 
  [action] => action 
  [regx] => |^(.+)/([_0-9a-zA-Z-]+)[/]?$| 
  [format] => %s/%s 
  [params] => Array ( [0] => permalink [1] => type ) 
) 
[page] => Array ( 
  [url] => /[slug].html 
  [widget] => Widget_Archive 
  [action] => render 
  [regx] => |^/([^/]+)\.html[/]?$| 
  [format] => /%s.html 
  [params] => Array ( [0] => slug ) 
) 

数据库中的位置

默认的路由信息存储在数据表“typecho_options”中,字段名是“routingTable”;

select * from typecho_options where name='routingTable';

在typecho中的调用

如下语句可以将路由表打印在前端页面上,当然仅仅只是排查之用,谁也不愿意在前端看到这么一堆乱糟糟的数据。

<?php print_r(Helper::options()->routingTable);?>

标签: typecho

移动端可扫我直达哦~

推荐阅读

typecho 2024-04-20

typecho根据标签的slug name信息判断是否输出免责声明

博主是从事机械行业的,工作过程中接触了很多二手老旧的设备,因为是二手设备,不缺胳膊少腿能正常运行已是难得,完善的说明书与售后服务想都不要想了。所以找设备的说明书成了一项附加的工作,总得让设备正常运行起来,偶尔设备有个小病小痛的,也不能...

建站相关 typecho

typecho 2023-11-02

Typecho开发文档-Widget设计文档

什么是WidgetWidget是组成Typecho的最基本元素,除了已经抽象出来的类库外,其它几乎所有的功能都会通过Widget来完成.在实践中我们发现,在博客这种小型但很灵活的系统中实施一些大型框架的思想是不合适的,它会使系统灵活性...

建站相关 typecho

typecho 2023-10-21

Typecho自动更新指定文章内容的尝试

曾经在老的博客(wordpress)里尝试并且成功运行过的一个方案,定时去请求某个比如“每天60秒读懂世界”这样的api,获取到数据,然后根据数据更新某一篇博文的内容。因为有“轻微”的强迫症,所以习惯把不用的东西直接“rm -rf”删...

建站相关 typecho

typecho 2023-10-21

Typecho数据库常用API

表的创建和删除在Typecho插件开发过程中,往往需要创建自己的表。上文提到Typecho_Db类中的query函数,可用于执行所有sql语句,因此我们使用query()来进行表的创建、修改或者删除。$db= Typecho_Db::...

建站相关 typecho

typecho 2023-10-18

让typecho博客支持显示数学公式

MathJax是一个开源的基于Ajax的数学公式显示的解决方案,结合多种先进的Web技术,支持主流的浏览器。MathJax根据页面中定义的LaTex数据,生成对应的数学公式。具体可见:mathjax项目代码(GitHub)因为是利用j...

建站相关 typecho

typecho 2023-10-15

为Typecho编辑器增加HTML标签支持

这几天为Typecho编辑器基本不支持块级元素而困扰,在github上翻编辑器插件的时候意外看到有位望友说可以去修改Hyperdown.php文件以增加对HTML标签的支持。该文件位于:build/var/HyperDown.php需...

建站相关 typecho

typecho 2023-10-12

typecho为什么更换主题后部分图片无法正确显示

其实严格的说,这可能是博主自己主题的问题,但人类的悲欢偶尔相通么,没准也可能在其他的主题中遇到类似的。博主之前边写博客边修改拼凑了一个比较简陋的主题,使用一段时间后,觉得主页过于单调了,于是在23年的国庆前后对主题整体做了一个比较大的...

建站相关 typecho

typecho 2023-10-05

typecho输出标签云或生成热门标签

小鸟数据生成标签云的代码应该是仿自默认的纯白主题,为了显示彩色标签,所以为tags增加了几个随机的类,事实上这几个类完全可以利用jquery在前端添加,毕竟现在用户的电脑性能远远超过了自己小水管服务器的性能,php添加随机类的写法:&...

建站相关 typecho