具体函数dr_show_url参考:
/** * 模块内容URL地址 * * @param array $mod * @param array $data * @param mod $page * @return string */ function dr_show_url($mod, $data, $page = NULL) { if (!$mod || !$data) { return SITE_URL; } $page && $data['page'] = $page = is_numeric($page) ? max((int)$page, 1) : $page; $ci = &get_instance(); $cat = $mod['category'][$data['catid']]; $rule = $ci->get_cache('urlrule', (int)$cat['setting']['urlrule'], 'value'); if ($rule && $rule['show']) { // URL模式为自定义,且已经设置规则 $data['modname'] = $mod['dirname']; $cat['pdirname'].= $cat['dirname']; $data['dirname'] = $cat['dirname']; $inputtime = isset($data['_inputtime']) ? $data['_inputtime'] : $data['inputtime']; $data['y'] = date('Y', $inputtime); $data['m'] = date('m', $inputtime); $data['d'] = date('d', $inputtime); $data['pdirname'] = str_replace('/', $rule['catjoin'], $cat['pdirname']); $url = ltrim($page ? $rule['show_page'] : $rule['show'], '/'); // 兼容php5.5 if (version_compare(PHP_VERSION, '5.5.0') >= 0) { $rep = new php5replace($data); $url = preg_replace_callback("#{([a-z_0-9]+)}#Ui", array($rep, 'php55_replace_data'), $url); $url = preg_replace_callback('#{([a-z_0-9]+)\((.*)\)}#Ui', array($rep, 'php55_replace_function'), $url); unset($rep); } else { $url = preg_replace('#{([a-z_0-9]+)}#Uei', "\$data[\\1]", $url); $url = preg_replace('#{([a-z_0-9]+)\((.*)\)}#Uie', "\\1(dr_safe_replace('\\2'))", $url); } return dr_uri_prefix('rewrite', $mod, $cat, 0).$url; } return dr_uri_prefix('cat_show_ext_php', $mod, $cat, 0).'c=show&id='.$data['id'].($page ? '&page='.$page : ''); }
那么如何在自己编写的工具类里面调用呢?参考如下:
注意第三个参数一定要带上后台URL定义的所有需要使用到的数据
如果本文对你有帮助,欢迎打赏本站