StartMVC开发手册

可以快速上手的开发文档

手册目录

路由

路由

StartMVC的默认路由都是自动的,系统会根据URL自动载入指定的模块、控制器和操作方法,并传入参数。如果路由不做配置的话,系统会调用默认路由方式。

路由配置(支持两种方式)

方法一(简洁方式):

//简便方法
//(:any)代表任意字符
//(:num)代表纯数字
return
[
  ['(:any)','home/$1'],//隐藏home模块url(适用于单模块)
  ['article_(:num)','article/detail/$1'], //格式为/article_232.html
  ['category/(:num)','category/index/$1'],//格式为/category/232.html
  ['tag/(:any)','tag/$1'],//格式为/tag/中国.html
];

方法二(正则表达试):

配置的原理其实就是正则替换,它返回一个数组,每个数组元素就是一条规则。这个数组由两个元素组成,第一个是路由改写后的URL正则表达式,第二个是路由需要改写的原URL。

// config/route.php
return
[
  ['/^about$/', 'home/index/about'],    // about 等于 home/index/about
  ['/^article\/(\d+)$/', 'home/index/article/$1']    // article/2 等于 home/index/article/2
  ['/^category\/(.*?)$/','home/category/index/$1'],
  ['/^about$/', 'home/index/about'],
  ['/^column\/(\d+)$/', 'home/index/column/$1']

];