boa框架开发手册v5.2

生成URL

生成URL的方法如下:


$param = [
	'name' => 'test',
	'id' => 1
];
$url = boa::router()->url('home.content.show', $param);
	

匹配路由

如果开启路由功能,将优先检索路由表,假设匹配以下路由规则:


[
	'url' => '/content/{name}/5-{id}/',
	'act' => 'home.content.show'
]
	
将得到$url为:/content/test/5-1/

未获匹配

如果关闭路由功能或未获匹配,将按照URL类型(type)生成URL:

  • type=0:$url = '/index.php?m=home&c=content&a=show&name=test&id=1'
  • type=1:$url = '/index.php/home/content/show/name-test/id-1/'
  • type=2:$url = '/home/content/show/name-test/id-1/'

额外参数

对于路由规则中额外的参数,将以QUERY_STRING的方式附加在匹配到的url后面,比如:


$param = [
	'name' => 'test',
	'id' => 1,
	'more' => 'a',
	'other' => 2
];
$url = boa::router()->url('home.content.show', $param);
	
匹配后$url = '/content/test/5-1/?more=a&other=2',未获匹配时URL生成规则如前所述