关于伪静态的问题,我有一个问题询问各位大佬。
是这样的我做的网站主目录是按照年代走的,比如2012、2013之类的,每个分目录下都有一个A、B的子目录,但是因为目录名字不能重复所以是A2012、A2013这样形式的。
URL规则组合起来就是【2012\A2012、2013\A2013】这样形式的不好看,就用自定义函数给去掉后面的2012和2013变为【2012\A、2013\A】。
但是在伪静态解析就出现问题了,比如我用正则表达式:
([\w]+)\/(A)
来取得出来的是:
$1=2012,$2=A
到这里取出都是没问题的,但是因为想指向到2012A这个目录,肯定是希望$2+$1得出A2012这样子的,就在后面写的是:
index.php?c=category&dir=$2$1
结果发现这里不会相加,这里会到
index.php?c=category&dir=A
这个地址,因为没有A这个栏目就提示栏目(A)不存在。。。
其实简单的就是想问如何将解析规则中的变量$1和$2之类的相加。。。
先感谢诸位大佬。
结果也是一样的只会指向 index.php?c=category&dir=19 导致如下结果:
<?php namespace Phpcmf\Controllers; // 曲线救国线路 class Mycategory extends \Phpcmf\Home\Module { public function index() { $page = max(1, (int)\Phpcmf\Service::L('input')->get('page')); $module = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-share'); if (!$module) { $this->_msg(0, dr_lang('共享栏目缓存不存在')); return; } $dir = ''; $dir1 = dr_safe_replace(\Phpcmf\Service::L('input')->get('dir1')); $dir2 = dr_safe_replace(\Phpcmf\Service::L('input')->get('dir2')); if (preg_match('/([0-9]+)$/U', $dir1, $one)) { // 找到数字,组合目录 $dir = $one[1].$dir2; } else { $this->_msg(0, dr_lang('参数1没有数字')); } $id = intval($module['category_dir'][$dir]); $cat = $module['category'][$id]; if (!$cat) { // 返回无法找到栏目 exit($this->goto_404_page(dr_lang('栏目(%s)不存在', $dir))); } // 初始化模块 if ($cat['tid'] == 1) { if ($cat['mid']) { $this->_module_init($cat['mid']); } else { exit($this->goto_404_page(dr_lang('栏目所属模块不存在'))); } } else { $this->_module_init('share'); } // 调用栏目方法 $this->_Category($id, $dir, $page); } }