有人可以告诉我如何在 SEF URL 的开头添加一个段 - 即:
http://somedomain.com/*SEGMENT*/task/id
*SEGMENT*只是一个静态字符串,只是为了显示而不是从查询中获取。
我的组件中有一个非常基本的 router.php:
function MyComponentBuildRoute(&$query)
{
$segments = array();
if (isset($query['task'])) {
$segments[] = $query['task'];
unset($query['task']);
}
if (isset($query['id'])) {
$segments[] = $query['id'];
unset($query['id']);
}
return $segments;
}
function MyComponentParseRoute($segments)
{
$vars = array();
$count = count($segments);
if ($count) {
$count--;
$segment = array_shift($segments);
if (is_numeric($segment)) {
$vars['id'] = $segment;
} else {
$vars['task'] = $segment;
}
}
if ($count) {
$count--;
$segment = array_shift($segments) ;
if (is_numeric($segment)) {
$vars['id'] = $segment;
}
}
return $vars;
}
希望有人能帮忙!