addonUrl( )应用URL生成【常用】

/**
* 扩展应用 URL 生成
* @author geeson myrhzq@qq.com
* @param $url string 应用url/应用名称/控制器/方法
* @param $arr array 参数
*/
function addonUrl($url = '', $vars = '', $suffix = true, $domain = false)
{
if (!empty($addonRule = session('addonRule')) || $url != '') {
$addonName = isset($addonRule['addon']) ? $addonRule['addon'] : '';
$addonController = isset($addonRule['col']) ? $addonRule['col'] : '';
$addonAction = isset($addonRule['act']) ? $addonRule['act'] : '';
$node = '';
if ($url == '') {
$node = $addonName . DS . $addonController . DS . $addonAction;
} else {
$nodeArr = array_values(array_filter(explode('/', $url)));
switch (count($nodeArr)) {
case 1:
$node = $addonName . DS . $addonController . DS . $nodeArr[0];
break;
case 2:
$node = $addonName . DS . $nodeArr[0] . DS . $nodeArr[1];
break;
case 3:
$node = $node = $nodeArr[0] . DS . $nodeArr[1] . DS . $nodeArr[2];
break;
}
}
if (!empty($mid = input('mid'))) {
if (is_array($vars)) {
$vars = array_merge($vars, ['mid' => $mid]);
} elseif ($vars != '' && !is_array($vars)) {
$vars = $vars . '&' . 'mid=' . $mid;
} else {
$vars = ['mid' => $mid];
}
}
$url = \think\Url::build(ADDON_ROUTE . $node, $vars, $suffix, $domain);
return $url = str_replace('.' . config('template.view_suffix'), '', $url);

}
}

0 个评论

要回复文章请先登录注册